Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在反射中获取字段的类型?我已经尝试过FieldInfo.Name其他一些选择,但没有成功。
FieldInfo.Name
假设我有int x = 5;. 我怎样才能得到"System.Int32"or"int"字符串?
int x = 5;
"System.Int32"
"int"
你想要的是FieldInfo.FieldType。
如果您想要完整的类型名,请使用;
myFieldInfo.FieldType.FullName
string type = x.GetType().FullName;
类型将是:"System.Int32"
使用 GetType 方法 -x.GetType().Name;
x.GetType().Name;