Introducing Radical.sh

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

Getting datatype of a variable in C#

Now you can know the datatype of a variable easily.
Remember that the variable must be assigned before using GetType() function.

C# will only look the value assigned and provide the result.

  1. using System;
  2.  
  3. namespace ConsoleApplication1
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9.  
  10. int i=2142324223;
  11.  
  12. System.Type tp = i.GetType();
  13.  
  14. Console.WriteLine(tp);
  15.  
  16.  
  17. string s = "forget code";
  18.  
  19. System.Type tp1 = s.GetType();
  20.  
  21. Console.WriteLine(tp1);
  22.  
  23. }
  24.  
  25. }
  26. }


Output:
  1. System.Int32
  2. System.String



..