Support us .Net Basics C# SQL ASP.NET ADO.NET MVC Slides C# Programs Subscribe Buy DVD

Part 8 - C# Tutorial - Arrays in C#

Suggested Videos
Part 5 - Operators 
Part 6 - Nullable Types
Part 7 - Datatype Conversions

In this video, we will discuss
1. Arrays
2. Advantages and dis-advantages of arrays



An array is a collection of similar data types.

using System;
class Program
{
    public static void Main()
    {
        // Initialize and assign values in different lines
        int[] EvenNumbers = new int[3];
        EvenNumbers[0] = 0;
        EvenNumbers[1] = 2;
        EvenNumbers[2] = 4;

        // Initialize and assign values in the same line
        int[] OddNumbers = { 1, 3, 5};

        Console.WriteLine("Printing EVEN Numbers");

        // Retrieve and print even numbers from the array
        for (int i = 0; i < EvenNumbers.Length; i++)
        {
            Console.WriteLine(EvenNumbers[i]);
        }

        Console.WriteLine("Printing ODD Numbers");

        // Retrieve and print odd numbers from the array
        for (int i = 0; i < OddNumbers.Length; i++)
        {
            Console.WriteLine(OddNumbers[i]);
        }
    }
}



Advantages: Arrays are strongly typed.

Disadvantages: Arrays cannot grow in size once initialized. Have to rely on integral indices to store or retrieve items from the array.

6 comments:

  1. i like your videos . they really helped me alot

    ReplyDelete
  2. Can you please explain the params type arrays?

    ReplyDelete
    Replies
    1. See Part 17 method parameters

      Delete
  3. Raju Goud BoyapalyAugust 15, 2015 at 8:29 PM

    its very help full to who don't have money to learn languages....thank you venkat sir. thank you soo much.

    ReplyDelete
  4. Thank you so much Sir Venkat ! Your tutorials are very awesome :-)

    ReplyDelete
  5. Thank you so much sir....You've really been helping me a lot and i appreciate it.

    ReplyDelete

If you like this website, please share with your friends on facebook and Google+ and recommend us on google using the g+1 button on the top right hand corner.