Data Type and Array

Only available on StudyMode
  • Download(s) : 66
  • Published : April 26, 2013
Open Document
Text Preview
How to use array in c# 5

In this tutorial I am going to explain about these questions answer below help of example in c# in visual studio 2012. 1. What is array? 
2. How to declare an array in c#  or How to Initializing Array? 3. How to assigning values to the array in c# ?
4. How to use array in c# with example?
5. How  to find even odd numbers in c# using array?
What is array?
An array is a collection of values of the same data type. The variables in an array are called the array elements. Array elements are accessed using a single name and an index number representing the position of the element within the array. Array is a reference type data type. The following figure shows the array structure in the system’s memory:

An array needs to be declared before it can be used in a program. You can declare an array by using the following statement: Source code|    |
int[] Score;
int[] Score;|
How to declare an array in c# with example step by step tutorial The following is an example of the array declaration:

The explanation of the elements of the preceding statement is as follows: datatype[] Arrayname;|
* datatype: Is used to specify the data type for the elements, which will be stored in the array. * [ ]: Is used to specify the rank of the array. Rank is used to specify the size of the array. * Arrayname: Is used to specify the name of the array using which the elements of the array will be initialized and manipulated. Initializing Array:-

Array is a reference type, therefore you need to use the new keyword to create an instance of the array. The following statement is an example of array initialization: The preceding two statements can be combined into a single statement, and written, as follows: Source code|    |

int[] Score = new int[10];
In C#, the array subscript always starts with zero.
Assigning values to the array:-
You can assign values to each element...
tracking img