Wednesday, November 10, 2021

Array declaration in asp.net (C#) - Type of variable declaration - Array declaration

1) string[] ss = new string[5];

             int[] i = new int[5];

i[0] = 1;

i[1] = 2; ........ //So on upto 5

                

         2)       int[] p = {6,7,8 };

        3)        int[] p1 = new int[2]{ 6,6 }; 

4) int[] evenNumbers;

evenNumbers = new int[5]; // or evenNumbers = new int[]{ 2, 4, 6, 8, 10 };

5) string[] array = new[] { "A", "B" };

6) string[] array = ["A", "B"];

ref:- https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/arrays

    https://stackoverflow.com/questions/5678216/all-possible-array-initialization-syntaxes

No comments:

Post a Comment