C#: Using property to retrieve string length

The power of automatic property can be seen in how we can easily retrieve the length of a string.

using System;

namespace StringLength
{
    class Program
    {
        static void Main()
        {
            string str = "Hello, World";
            int strLength = str.Length;

            Console.WriteLine(strLength);
            Console.ReadKey();
        }
    }
}

Length is a property of string.  As shown in the above code, we just have to use str.Length to retrieve its length.

Series Navigation<< C#: Automatic Properties
C#: Get & set for auto-implemented properties >>