Variable एक Name है जिसे Storage Area दिया जाता है जिसे हमारे Programs Manipulate कर सकते हैं।
C# में प्रत्येक Variable का एक Specific Type होता है, जो Variable की Memory के Size और Layout, उस Memory में Store की जा सकने वाली Values की Range और Variable पर Apply किए जा सकने वाले Operations के Set को Determine करता है।
Variable को Initialize करने के लिए, पहले आपको इसे Define करना होगा।
int a;
अब Initialize करने के लिए, Constant Expression के बाद Equal Sign का उपयोग करें।
int a = 10;
हमने ऊपर निम्न Syntax का उपयोग किया।
variable_name = value;
आइए C# में Variable के साथ काम करने का एक Simple Example देखते हैं।
Example
using System; namespace VariableDefinition { class Program { static void Main(string[] args) { short a; int b; double c; a = 10; b = 20; c = a + b; Console.WriteLine("a = {0}, b = {1}, c = {2}", a, b, c); Console.ReadLine(); } } }Output
a = 10, b = 20, c = 30