呵呵,你是说异常吧?
这是Msdn中 Object.GetType Method [C#] 专题的内容,希望对你有帮助Gets the Type of the current instance.[Visual Basic]
<Serializable>
<ClassInterface(ClassInterfaceType.AutoDual)>
Public Function GetType() As Type
[C#]
[Serializable]
[ClassInterface(ClassInterfaceType.AutoDual)]
public Type GetType();
[C++]
[Serializable]
[ClassInterface(ClassInterfaceType.AutoDual)]
public: Type* GetType();
[JScript]
public
Serializable
ClassInterface(ClassInterfaceType.AutoDual)
function GetType() : Type;
Return Value
The Type instance that represents the exact runtime type of the current instance.Res
For two objects x and y that have identical runtime types, Object.ReferenceEquals(x.GetType(),y.GetType()) returns true.The Type object exposes the metadata associated with the class of the current Object.Example
[C#, JScript] The following code example demonstrates that GetType returns the runtime type of the current instance.[C#]
using System;public class MyBaseClass: Object {
}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());
}
}
/*This code produces the following output.mybase: Type is MyBaseClass
myDerived: Type is MyDerivedClass
object o = myDerived: Type is MyDerivedClass
MyBaseClass b = myDerived: Type is MyDerivedClass */
这是Msdn中 Object.GetType Method [C#] 专题的内容,希望对你有帮助Gets the Type of the current instance.[Visual Basic]
<Serializable>
<ClassInterface(ClassInterfaceType.AutoDual)>
Public Function GetType() As Type
[C#]
[Serializable]
[ClassInterface(ClassInterfaceType.AutoDual)]
public Type GetType();
[C++]
[Serializable]
[ClassInterface(ClassInterfaceType.AutoDual)]
public: Type* GetType();
[JScript]
public
Serializable
ClassInterface(ClassInterfaceType.AutoDual)
function GetType() : Type;
Return Value
The Type instance that represents the exact runtime type of the current instance.Res
For two objects x and y that have identical runtime types, Object.ReferenceEquals(x.GetType(),y.GetType()) returns true.The Type object exposes the metadata associated with the class of the current Object.Example
[C#, JScript] The following code example demonstrates that GetType returns the runtime type of the current instance.[C#]
using System;public class MyBaseClass: Object {
}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());
}
}
/*This code produces the following output.mybase: Type is MyBaseClass
myDerived: Type is MyDerivedClass
object o = myDerived: Type is MyDerivedClass
MyBaseClass b = myDerived: Type is MyDerivedClass */
给你一段简单的程序,你试试。
private void Form1_Click(object sender, System.EventArgs e)
{
try
{
int i1=2;
int i2=0;
int i=i1/i2;
}
catch(Exception ee)
{
MessageBox.Show(ee.GetType().ToString());
}
}
3x