Support us .Net Basics C# SQL ASP.NET Aarvi MVC Slides C# Programs Subscribe Download

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.

13 comments:

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

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

    ReplyDelete
  3. 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
  6. hello I really like the way you teach .
    I am new to c# .you have not written Console.ReadLine in any of your video without that we cannot see the output .May I know the reason behind that ?? I need to complete the c# course before april 20 .I am doing that from your videos but I need to do practice as well .Is it possible for you to give me practice examples or teach on skype on payable basis .The reason on skype is I am in Toronto can't attend your course personally.
    Thanks

    ReplyDelete
  7. why we use int[] and new int[]? what [] do ?

    ReplyDelete
    Replies
    1. int[]->It indicates that we are initializing array
      = new int[] -> it indicates that we are allocating size to array

      Delete
    2. [] is a symbol for array .. [] sign tells the compiler that we are going to make an array.

      Delete
  8. Let me know what is strongly typed or why arrays are strongly typed?

    ReplyDelete
    Replies
    1. Strongly typed means that an Array can hold only specific datatype values in an array variable in which you cannot add any other value other than the specified datatype values.

      For instance, int[] intArr = new int[3];
      You can specify intArr[1]=1233;
      If you try to assign intArr[1] = "YourName"
      you will be prompted with Compiler error.

      Delete

It would be great if you can help share these free resources