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:
using System;
class GFG {
public static void Main()
{
string str1 = "Geeksforgeeks" ;
int a = 12;
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:
using System;
class GFG {
public static void Main()
{
String str1 = "Geeks" ;
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:
Last Updated :
01 Feb, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...