C#: Using property to retrieve string length

This entry is part 30 of 71 in the series C#

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;


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 >>