(1)Variable and Data types:
This is how you will declare a variable.
string Vaibhav;
int a;
You can also declare a variable by using the type name from the
.NET class library.
System.Int32 errorCode;
System.String myName;
Remember c# variable and .NET type name are different.
See
C# ASP.NET
int int32
long int64
short int16
byte byte
float single
double double
char char
string string
bool boolean
object object
(2)Assignment:
// Declare variables.
int a;
string myName;
// Assign values.
a = 10;
myName = "Adarsh";
or you can do this
int a=10;
string myName="Adarsh";
This doesnt make any sense..it will cause a error
int number;
number=number+1;
because you havent assigned any value
but if you do such
int number=0;
number=number+1;
than variable number will contain 1
C# also deals strictly with data types. For example, the following code statement won’t
work as written:
decimal myDecimal = 14.5;
for following strictness is applied
• M (decimal)
• D (double)
• F (float)
• L (long)
so u have to write
decimal myDecimal=14.5M;
but if you use this type of variables than you can also use
var myDecimal=14.5M
Have a nice day
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment