Introducing Radical.sh

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

Explicit Casting in C#

The following code explains Explicit casting.

  1. using System;
  2. using System.Text;
  3.  
  4. namespace forgetCode
  5. {
  6.  
  7. class program
  8. {
  9. public static void Main()
  10. {
  11. // Assign an integer and then cast it to an object implictly.
  12. int value1 = 10;
  13. object value2 = value1;
  14.  
  15. // Explicitly cast to an integer again from the object type.
  16. int value3 = (int)value2;
  17. Console.WriteLine(value3);
  18.  
  19. }
  20. }
  21. }


Output:
10