Skip to main content

C# Tutorial, Arrays

Hi, Welcome to all. My name is Abdul Yesdani. Today we are going to learn about arrays in C#.

In our previous postings we have worked with variables. One variable can store only one value. If we want to store multiple values of same type, array variable is there to do that job.

What is an array?

An array variables is capable of storing multiple values of same type.  

Syntax:  datatype[ ] arrayName = new datatype[size];

Example: int [ ] myNumbers = new int [ 5];

 The above array variable  myNumbers is capable of storing 5 integer values.

In the memory it will allocate 5 slots to store 5 values, index starting from 0 to 4. Array indexing will always start with 0 and end with size -1.

Types of Arrays in C# :

There are 3 types of array in C#.  Single dimensional array, multi dimensional array and jagged array.

Single dimension array represent a single column or row of values. The above example is for the same.


Multi dimension array represent 2 dimension or 3 dimension or 'n' dimension of arrays. You can assume it as an array of arrays.

example: int [ , ] twoDarray = new int[3,4]; We can print 3 rows with 4 columns matrix.




Jagged array represent 'n' number of arrays with each one having varied length.

example: int [ ][ ]  jaggedarray = new int[3][ ];

               jaggedarray[0]= new int[3]{34,45,56};

               jaggedarray[1] = new int[2 ] {33,99};

               jaggedarray[2]= new int[5 ] {10,20,30,40,50};



watch video








 

Comments

Post a Comment

Popular posts from this blog

.Net Presentation

.NET is a free, cross-platform, open source developer platform for building many different types of applications. With .NET, you can use multiple languages, editors, and libraries to build for web, mobile, desktop, games, and IoT. You can write .NET apps in C#, F#, or Visual Basic. C# is a simple, modern, object-oriented, and type-safe programming language. F# is a programming language that makes it easy to write succinct, robust, and performant code. Visual Basic is an approachable language with a simple syntax for building type-safe, object-oriented apps. You can write .NET apps in C#, F#, or Visual Basic. C# is a simple, modern, object-oriented, and type-safe programming language. F# is a programming language that makes it easy to write succinct, robust, and performant code. Visual Basic is an approachable language with a simple syntax for building type-safe, object-oriented apps.

Bootstrap

  Bootstrap is a powerful, feature-packed frontend toolkit. Build anything—from prototype to production. Bootstrap includes HTML and CSS based design templates for typography, forms, buttons, tables, navigation, modals, image carousels and many other, as well as optional JavaScript plugins Bootstrap also gives you the ability to easily create responsive designs. Get started by including Bootstrap’s production-ready CSS and JavaScript via CDN without the need for any build steps.