Student Of Fortune

C# Tips, Array Implementation In C#

Share on :
Arrays are one type of data that consists of several elements or a set of values from a set of similar variables. For more details, see the picture as follows: If we declare a variable as an example int a = 10; then in the computer memory will store the name of the variable along with the value.
 The difference with the array is, in a variable that is declared as an array, he could save more than one value at a different index

In the picture above can be understood that the variable array "A " with type integer has a value of 10 on the index-0, 11 in the index to-1, 19 on the index-2, and 27 on the index to 3. Thus the array "A" has a length of 4 and has a data type integer.
Here is a sample array program in C #.
See The Code :
using System;
namespace UsingArray
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] array = new int[10];
            Console.WriteLine("Index\tValue");
            for (int counter = 0; counter < array.Length; counter++)
                Console.WriteLine(counter+"\t"+array[counter]);
        }
    }
}
See The Output Of Code :
Index  Value    
0      0    
1      0    
2      0    
3      0    
4      0    
5      0    
6      0    
7      0    
8      0    
9      0 
The above example is an array that has not been rated yet, so every index in the array will contain the value 0 by C #, well then we will discuss about how to assign values to the array, consider the example program below:
See The Code :
using System;
namespace InputOutput
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] array = { 32, 27, 64, 18, 95, 14, 90, 70, 60, 37 };
            Console.WriteLine("Index\tValue");
            for (int counter = 0; counter < array.Length; counter++)
                Console.WriteLine(counter+"\t"+array[counter]);
        }
    }
}
So when we compile, the output array is no longer worth 0, because already we fill the value in it.
See The Output Of Code :
Index  Value
0      32
1      27
2      64
3      18
4      95
5      14
6      90
7      70
8      60
9      37 
Reference :
http://yohandamandala.blogspot.com/2009/11/array-in-c.html

0 comments on C# Tips, Array Implementation In C# :

Post a Comment and Don't Spam!

Dont Spam please

 
Recommended Post Slide Out For Blogger

Recent Comments

My Rank