Introducing Radical.sh

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

Type Casting - Example in C#

This is the example program for CASTING.
Note that C# automatically converts the values implicitly.
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5.  
  6. namespace forgetCode
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12.  
  13. int iNumber = 100;
  14. long aLong1 = (long)iNumber;
  15. long aLong2 = (long)100;
  16.  
  17. double dNumber= iNumber;
  18.  
  19.  
  20. Console.WriteLine(iNumber);
  21. Console.WriteLine(aLong1);
  22. Console.WriteLine(aLong2);
  23.  
  24. Console.WriteLine(dNumber);
  25.  
  26.  
  27. }
  28.  
  29. }
  30. }
  31.  


  1. Output:
  2. 100
  3. 100
  4. 100
  5. 100