C# variables

C# variable types include byte, sbyte, short, ushort, int, uint, long, ulong, float, double, decimal, char, string, enum and reference. Variable name should be consisted with letter, number and slashes only, with a letter at the beginning position.

int i=3;
int i^r=3; //error, ^ is not allowed

Variable name should not be the same with the reserved keywords.
string ref="this is wrong"; //error, ref is a reserved keyword

Static variables exist when the class is loaded.
using System.Windows.Forms;
class tt
{
public static string str = "test variable";
public int i = 3;
public void tweet()
{
......
}
}
MessageBox.Show(tt.str); //test variable

Non static variables can be used only after the object is created.
using System.Windows.Forms;
class tt
{
public static string str = "test variable";
public int i = 3;
public void tweet()
{
......
}
}
MessageBox.Show(tt.i); //error
tt s = new tt();
MessageBox.Show(s.i.ToString()); //3


C# variable data types:

variable
bit
value range
sbyte
8 bit
-128 ~ 128, -27 ~ 27
byte
8 bit
0 ~ 255, 0 ~ 28
short
16 bit
-32768 ~ 32767, -215 ~ 215
ushort
16 bit
0 ~ 65535, 0 ~ 216
int
32 bit
-2147483648 ~ -2147483647, -231 ~ 231
unit
32 bit
0 ~ 4294967295, 0 ~ 232
long
64 bit
-9223372036854775808 ~ -9223372036854775807, -263 ~ 263
ulong
64 bit
0 ~ 18446744073709551615, 0 ~ 264
char
16 bit
floa
t32 bit
double
64 bit
decimal
128 bit

endmemo.com © 2017  Terms of Use | Home