Open In App

C# | How to get TypeCode for the class String

Last Updated : 01 Feb, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

GetTypeCode() method is used to get the TypeCode of the specified string.
Here TypeCode enum represents a specific type of object. In TypeCode every data type is represented by a specific number like String is represented by 18, Int32 is represented by 9, etc.

Syntax:

public TypeCode GetTypeCode ();

Return value: This method return an enumerated constant.

Below given are some examples to understand the implementation in a better way:

Example 1:




// C# program to illustrate the 
// GetTypeCode() Method
using System;
  
class GFG {
     
    // Main method
    public static void Main()
    {
  
        // variables
        string str1 = "Geeksforgeeks";
        int a = 12;
  
        // get the TypeCode by
        // using GetTypeCode() method
        Console.WriteLine("The TypeCode for {0}': {1}",
                              str1, str1.GetTypeCode());
  
        Console.WriteLine("The TypeCode for '{0}': {1}",
                                    a, a.GetTypeCode());
    }
}


Output:

The TypeCode for Geeksforgeeks': String
The TypeCode for '12': Int32

Example 2:




// C# program to illustrate the 
// GetTypeCode() Method
using System;
  
class GFG {
   
// Main method
public static void Main()
{
    // given string
    String str1 = "Geeks";
  
    // get the TypeCode of the given String
    // using GetTypeCode() method
    TypeCode g = str1.GetTypeCode();
    Console.WriteLine("TypeCode for '{0}': {1}, Which means it represents a {2}.",
                                          str1, g.ToString("D"), g.ToString("F"));
}
}


Output:

TypeCode for 'Geeks': 18, Which means it represents a String.

Reference:



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads