Arrays in C#

If we want to store a group of similar data types, we can make use of Arrays.

Write a program to save 3 even numbers in an integer array. Print the third number.


using System;
class Program
{
    static void Main()
    {
        int[] evenNumners = new int[3];

        evenNumners[0] = 0;
        evenNumners[1] = 2;
        evenNumners[2] = 4;

        //we can also define array as below:
        //int[] evenNumners = { 0, 2, 4 };

        Console.WriteLine(evenNumners[2]); //Output is 4
    }
}


Comments

Popular posts from this blog

Introduction to C#

Common Operators in C#

Built-in types in C#