dim a as textbox=new textbox()
dim b as type=gettype(textbox) or a.gettype()
dim b as type=gettype(textbox) or a.gettype()
解决方案 »
- 本机有多个IP,如何能为System.Net.NetworkInformation.Ping指定特定本机IP
- C# 串口通讯接收255(FF),有时却接收到(127).用串口助手打开端口后,又收到到255(FF)
- 如何用DataGridView 来显示出表的结构
- 新手问下:学习C#.NET 谁能推荐点资料书籍?万分感谢!!
- 请问一个模式窗体和无模式窗体的问题
- 把字符串放到表格中.......
- .net2005中自帶的水晶報表的布署打包用模塊在哪裡下載啊???
- c#程序FORM界面被压扁,郁闷中。。。
- 请高手指点一下下面一段代码!谢谢各位GG
- 简单问题
- DataGrid中的byte类型如何取出?
- linkbuttom有没有类似target的属性,怎么样才能达到同样的效果??
Type.GetType("AddressBookData");这样是得不到自己定义的类型啊。
好象比如底下这样的控件也不可以啊。
System.Windows.Forms.CheckBox
// don't forget your using statements at the top of your code...
Using System;
Using System.Reflection;// class declaration, and method declaration...// remember that this string is case-sensitive, so be careful
Type t = Type.GetType("System.String");// check to see if we have a valid value. If our object is null, the type does not exist...
if (t == null) {
// Don't assume that it is a SYSTEM datatype...
Console.WriteLine("Please ensure you specify only valid types in the type field.");
Console.WriteLine("REMEMBER: The Case matters (Byte is not the same as byte)."); return; // don't continue processing
}
這個範例說明如何擷取指定的組件 (Assembly) 的所有型別。若要看透組件的型別,您首先需要識別您想要操作的組件。一旦您擁有相關組件的物件參考,您就可以在那組件上呼叫 GetTypes 方法,其將傳回該組件中所有型別的陣列。您可以在那陣列中使用控制邏輯來識別更確定的型別,並使用重複邏輯來剖析您的陣列,在需要時傳回型別資訊給使用者。擷取型別資訊的能力將有助於判斷替代型別 (您可能運用在指定的工作),或識別現有項目以提供您所需的功能。
Visual Basic GetTypes.aspx [執行範例] | [檢視原始檔]
從特定組件擷取型別時,要學會的第一件事是,如何識別組件。這個快速入門示範兩個擷取組件的方式。第一個是,識別特定物件 (您想從中尋找組件的),並向組件要求那物件的模組 (請記得模組是型別和程式碼的邏輯群組,例如 .dll 或 .exe)。第二個則是,使用 Assembly 類別的 LoadFrom 方法,為具名的模組 (如 myapp.exe) 載入特定組件。
// don't forget your using statements
using System;
using System.Reflection;
// ...// Getting an Assembly, method 1. Get the mscorlib assembly
// Note that other types such as String, or Int32 would have worked just as well,
// since they reside in the same assembly
Assembly a = typeof(Object).Module.Assembly;// Getting an Assembly, method 2. Load a particular assembly, using a reference to a
// module that is within that assembly. Note that this requires a compiled module for
// the reference, and when running in an aspx page, will require a fully qualifed path
// to the file, to ensure it is correctly identified
Assembly b = Assembly.LoadFrom ("GetTypes.exe");// note that either of the above methods is viable, depending on the information
// you have. Since we know the name of the file which houses all of the base system
// objects, we could do the following to replace the first example, just as effectively
// (the absolute path may change on your machine)
// Assembly a = Assembly.LoadFrom
// ("c:/winserv/microsoft.net/framework/v1.0.2230/mscorlib.dll");
//Get all the types in the assembly identified in the previous example
Type [] types = a.GetTypes ();int numInterfaces = 0;foreach (Type t in types) { //the following line uses a set of methods which identify what
//kind of type we are currently querying
if (t.IsInterface) {
// only print out the names of the Interfaces
Console.WriteLine (t.Name + "");
numInterfaces++;
}
}// write out the totals
Console.WriteLine("Out of {0} types in the {1} library:",
types.Length, typeof(Object).Module.ToString());
Console.WriteLine ("{0} are interfaces (listed)", types.Length, numInterfaces);