(3)Array:-
To create a array of 4 string ,we use following syntax
string[] stringArray = new string[4];
to create array of 3 string
string[] stringArray = new string[3];
to create multidimensional array of integers
int[,] intArray = new int[2, 4];
this array contain 2 rows and 4 columns means 8 block
difference between one dimensional and multidimensional is just
a comma in bracket.
You can assign value in array like this
int[] intArray = {"1","2","3","4"};
int[,] intArray = {{1, 2}, {3, 4}, {5, 6}, {7, 8}};
Now if you want to assign a array in a variablie then
int a;
a=intarray[1,2];
Remember where is curly braces and where are square braces
(4)Array List:
It is a dynamic array.In normal array you cant change size
after you defined once.Here is syntax for dynamic array
ArrayList dynamicList = new ArrayList();
Now after initialization start flling in array
dynamicList.Add("one");
dynamicList.Add("two");
dynamicList.Add("three");
(5)Variable Operation:
+
-
*
=
/
%
number=4+ 3 +5;
Joining two strings
name=first name+""+last name;
(6)Advance Maths:
Double myValue;
myValue = Math.Sqrt(81); // myValue = 9.0
myValue = Math.Round(42.889, 2); // myValue = 42.89
myValue = Math.Abs(-10); // myValue = 10.0
myValue = Math.Log(24.212); // myValue = 3.18.. (and so on)
myValue = Math.PI; // myValue = 3.14.. (and so on)
I copied it from a book.. please dont mention
(7)Type conversion:
Converting information from one data type to another
Here how to change a 32-bit integer to a 16-bit integer:
int count32 = 1000;
short count16;
count16=(short)count32;
Take another example
int mySmallValue;
long myLargeValue;
// Get the largest possible value that can be stored as a 32-bit integer.
// .NET provides a constant named Int32.MaxValue that provides
this number.
mySmallValue = Int32.MaxValue;
// This always succeeds. No matter how large mySmallValue is,
// it can be contained in myLargeValue.
You should remember that a small value can not hold
a large no.It will cause a overflow and give a error
for example
int mySmallValue;
long myLargeValue;
myLargeValue = Int32.MaxValue;
myLargeValue++;
mySmallValue = (int)myLargeValue;
In C#, you can’t use casting to convert numbers to strings, or vice versa. In this case, the
data isn’t just being moved from one variable to another
But ASP.NET gives the solution
string a = "10";
int count = Convert.ToInt32(a);
it converts string value to numeric value
Now if we want to do vice versa thn
a= Convert.ToString(count);
In place of Convert you can also use parse
count = Int32.Parse(a);
Tomorrow we will finish c# .
Have a nice day
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment