Initializing variable in c#.net ?
We are learning a new language daily so we need to remember how too initialize variables in c#.net so bookmark this and use it as your daily guidebook to initialize variable in c#.net.
Initialize variables in C#.net
Single Dimensional Array
Integers
<code>
int[] n1= new int[4]{2,3,1,4};
int[] n2= new int[]{1,2,3,4};
int[] n3= {1,2,3,4,};
</code>
Strings
<code>
string[] s1= new string[4]{"tom","jerry","harry","ben"};
string[] s2= new string[]{"tom","jerry","harry","ben"};
string[] s3= {"tom","jerry","harry","ben"};
</code>
Multi-dimensional array.
Integer
<code>
int[,] n1 = new int[3, 2] { {1, 2}, {3, 4}, {5, 6} };
int[,] n2 = new int[,] { {1, 2}, {3, 4}, {5, 6} };
int[,] n3 = { {1, 2}, {3, 4}, {5, 6} };
</code>
String
<code>
string[,] n1 = new string["ben","tom"] { {"sam","joe"}, {"harry","jack"}, {"noa","nemo"} };
string[,] n2 = new string[,] { {"sam","joe"}, {"harry","jack"}, {"noa","nemo"}};
string[,] n3 = {{"sam","joe"}, {"harry","jack"}, {"noa","nemo"} };
</code>
Jagged array.
Integer
<code>
int[][] n1 = new int[2][] { new int[] {2,4,6}, new int[] {1,3,5,7,9} };
int[][] n2 = new int[][] { new int[] {2,4,6}, new int[] {1,3,5,7,9} };
int[][] n3 = { new int[] {2,4,6}, new int[] {1,3,5,7,9} };
</code>
String
<code>
string[][] n1 = new string[2][] { new string[] {2,4,6}, new string[] {1,3,5,7,9} };
string[][] n2 = new string[][] { new string[] {2,4,6}, new string[] {1,3,5,7,9} };
string[][] n3 = { new string[] {2,4,6}, new string[] {1,3,5,7,9} };
</code>
Comments
Post a Comment