C# Byte GetType
Description
Byte GetType
gets the Type of the current instance.
Syntax
Byte.GetType
has the following syntax.
public Type GetType()
Returns
Byte.GetType
method returns The exact runtime type of the current instance.
Example
The following example uses the GetType method with the ReferenceEquals method to determine whether one numeric value is the same type as two other numeric values.
using System;/*from w ww .j a v a 2 s . c om*/
public class MainClass {
public static void Main(String[] argv){
int n1 = 12;
int n2 = 82;
long n3 = 12;
Console.WriteLine("n1 and n2 are the same type: {0}",
Object.ReferenceEquals(n1.GetType(), n2.GetType()));
Console.WriteLine("n1 and n3 are the same type: {0}",
Object.ReferenceEquals(n1.GetType(), n3.GetType()));
}
}
The code above generates the following result.
Example 2
The following code example demonstrates that GetType returns the runtime type of the current instance.
using System;// w w w . j a va 2 s .c om
public class MyBaseClass {
}
public class MyDerivedClass: MyBaseClass {
}
public class Test
{
public static void Main()
{
MyBaseClass myBase = new MyBaseClass();
MyDerivedClass myDerived = new MyDerivedClass();
object o = myDerived;
MyBaseClass b = myDerived;
Console.WriteLine("mybase: Type is {0}", myBase.GetType());
Console.WriteLine("myDerived: Type is {0}", myDerived.GetType());
Console.WriteLine("object o = myDerived: Type is {0}", o.GetType());
Console.WriteLine("MyBaseClass b = myDerived: Type is {0}", b.GetType());
}
}
The code above generates the following result.