Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Casting between String and Object types in C#

The following code explains the Casting between String and Object types.

using System;
using System.Text;

namespace forgetCode
{

    class program
    {
        public static void Main()
        {
            // Assign string and then cast it to an object implictly.
            string  value1 = "hi";
            object value2 = value1;

            // Explicitly cast to string again from the object type.
            string value3 = (string)value2;
            Console.WriteLine(value3);

        }
    }
}


Output:
hi