By 22/07/2015 13 Comments

C# Cast Operator

  • It is denoted by ( ) symbol.
  • Cast operator is used for an explicit casting, means that operator is define a target type. Such as (int).

Example:

using System;
namespace csharpBasic
{
  // Start class definition / declaration.
    class Program
    {
      // Static main method void type declaration.
        static void Main(string[] args)
        {
            // Declare and initialize anyNumber variable with 2.
            int anyNumber = 2;

            // Declare a char type variable ch.
            char ch;

            /* This statement performing an explicit castinging though cast operator (char), 
               an int type variable is being converted into a character data type. */
            ch = (char)anyNumber;

            // Print above result.	  
            Console.WriteLine("Cast or convert an int type to char: {0} ", ch);
            Console.ReadKey();

        } // End of main method definition.

    } // End of class.
}






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 .