By 22/07/2015 12 Comments

Array Length Property In C#

  • C# Array Length Property is a built-in property in Array class.
  • The length property has an int as its return type and returns the total number of elements / values which can be hold by an array.
  • It is read only property that means we can only use / print it.
  • The length property can be called as: array-name.length, where array-name is a name of an array, dot operator joins an array with the length property.
  • The length property can be used with all array types such as ,single dimensional, jagged, 2D array etc.

Example:

using System;
namespace csharpBasic
{
    class Program
    {
        static void Main(string[] args)
        {
       // A string type single dimensional array declaration.
            string[] studentsSeatNumbers = new string[7];

       // An array length is being assigned to a local int type variable.
            int arrayLength = studentsSeatNumbers.Length;

       // An Array length is being printed.
            Console.WriteLine("The length of studentsSeatNumbers array is: {0}", arrayLength);
            Console.ReadKey();
        }
        /*
        The Output will be:
        
        The length of studentsSeatNumbers array is: 7
       */
    }
}





Next Tutorial →


← Previous Tutorial


Posted in: C# Basics, C#.NET

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .