Click here to Skip to main content
15,915,694 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,I have doubt regarding getting the return types .

C#
class SampleOnOUTandREF
{

    static void Main(string[] args)
    {
        Console.Write(typeof(int));
        Console.Read();
    }
}


If i write this the output is System.Int32.
But in my application i want the result as "int" if i give "System.Int32". Please help regarding this issue.In my application i am using System.Reflection for reading .dll's.
Posted
Updated 12-Oct-10 2:18am
v2

AFAIK you can't without coding special case stuff - "int" is just syntactic sugar for Int32.
 
Share this answer
 
int, bool, float, double etc. are only C# keywords that represent the .NET CLR types System.Int32, System.Boolean, System.Single, System.Double etc.

If you need the C# keywords instead of full type names, I think you will have to write your own conversion method. See the complete list of C# built-in types.
 
Share this answer
 
int is not a Type. It is a C# keyword aliasing System.Int32, which is the Type.
Please take into consideration the fact that C#.NET is not the only .NET programming language. In VB.NET (God forbid) int means nothing, even less a Type.
Please also notice the different automatic coloring. The first int is blue (C#, a keyword), the second one is plain (vb, ordinary identifier).
So, you can only get System.Int32 as an answer, because your class / assembly can be used from any .NET compatible language, not only C#, where int has a meaning.
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900