獲取 C# 指定物件型別的控制代碼
要獲取指定物件的型別的控制代碼,程式碼如下 −
示例
using System;
public class Demo {
public static void Main() {
Type type1 = typeof(System.Type);
RuntimeTypeHandle typeHandle = Type.GetTypeHandle(type1);
Type type = Type.GetTypeFromHandle(typeHandle);
Console.WriteLine("Attributes = " + type.Attributes);
Console.WriteLine("Type Referenced = "+ type);
}
}輸出
將產生以下輸出 −
Attributes = AutoLayout, AnsiClass, Class, Serializable, BeforeFieldInit Type Referenced = System.RuntimeType
示例
我們來看另一個示例 −
using System;
public class Demo {
public static void Main() {
Type type1 = typeof(double);
RuntimeTypeHandle typeHandle = Type.GetTypeHandle(type1);
Type type = Type.GetTypeFromHandle(typeHandle);
Console.WriteLine("Attributes = " + type.Attributes);
Console.WriteLine("Type Referenced = "+ type);
}
}輸出
將產生以下輸出 −
Attributes = AutoLayout, AnsiClass, Class, Serializable, BeforeFieldInit Type Referenced = System.RuntimeType
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP