开发者

Is there an easy way to get Type object from C# type name

开发者 https://www.devze.com 2023-01-19 18:33 出处:网络
I want to create Type object from string value, e.g., \"int\", \"long\". I know I can create Type object from .net fr开发者_如何转开发amework type name, like

I want to create Type object from string value, e.g., "int", "long". I know I can create Type object from .net fr开发者_如何转开发amework type name, like Type t = Type.GetType("System.Int32").

Is there a built-in way to do same from C# type, "int", "long".


The .Net framework itself (including the Reflection library) is completely unaware of C#'s type keywords.
Therefore, you'll need to do this youself.

You can create a Dictionary<string, Type>.


Check out Reflection.


Given I didn't understand your question here is a link to this question asked previously

typeof(int), typeof(string);
0

精彩评论

暂无评论...
验证码 换一张
取 消