0

I want to create Type object from string value, e.g., "int", "long". I know I can create Type object from .net framework type name, like Type t = Type.GetType("System.Int32").

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

Zamacho
  • 11
  • 2

3 Answers3

4

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>.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
0

Check out Reflection.

Tyler Treat
  • 14,640
  • 15
  • 80
  • 115
0

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

typeof(int), typeof(string);
Community
  • 1
  • 1
rerun
  • 25,014
  • 6
  • 48
  • 78