C# | How to get TypeCode for the class String

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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());
    }
}

chevron_right


Output:

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

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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"));
}
}

chevron_right


Output:

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

Reference:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.