Arrays in C#

 Introduction:

Arrays are data type of fixed size, it is a data structure composed of columns and rows, it is a two dimensional data structure having a tabular kind structure with a column index and row index, here we would how we can use arrays in c#.

We are considering an array named as X, the size of array X is 6 from index 0 to 5, the first index of an array starts with index 0 and so on.

                                                                    Array X[6]

4

5

1

15

34

11

    X[0]                       X[1]                         X[2]                        X[3]                          X[4]                          X[5]

arrays can only stored data of fixed type, we can have arrays of string, arrays of Int, and so on, so we declare arrays in c# as 

datatype[] arrayname;

first we will have some data type followed by [] brackets and then the name of the array, where as [] determines the rank or the size of the array.

we can declare an array of int as 

int[] myarray=new int[10];

so it is an array being named as myarray of size 10, and the arrays indexing starts from myarray[0] to myarray[9].

Now, here we will consider an example to see how can arrays be used in c#, so first we will create a new project in Visual Studio as a console based application,



here , we will consider an example  of declaring an array and then prints out the sum of all those numbers inside the array.



So, now we will simple display the output, Press crtl+F5 to run the application and see the output window.



















 

 

 

 

               

Talha Mahmood

I have been developing Applications in Microsoft .NET technologies since 2015, and having more then 5 years of experience in .NET Technology and SQL database, also having hands in tools like C# Windows Forms, WPF, WCF, Asp.Net Web forms, Asp.Net Core, SSRS, LINQ, Entity Framework, Crystal Reports, SQL server, MySQL, MongoDB, Document DB, JQuery, JavaScript, Oracle, Web API.

Post a Comment

Previous Post Next Post