如何在C#中找到返回类型? [英] How to find the return type in C#?

查看:94
本文介绍了如何在C#中找到返回类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我对获取返回类型有疑问.

  class  SampleOnOUTandREF
{

    静态 无效 Main(字符串 []参数)
    {
        Console.Write( typeof ( int ));
        Console.Read();
    }
} 



如果我写这个,输出是System.Int32.
但是在我的应用程序中,如果我给出"System.Int32",我希望结果为"int".请帮助解决此问题.在我的应用程序中,我正在使用System.Reflection读取.dll文件.

解决方案

AFAIK您不能不编写特殊情况东西-"int"只是Int32的语法糖.


intboolfloatdouble等.仅是表示.NET CLR的C#关键字.类型System.Int32System.BooleanSystem.SingleSystem.Double等.

如果您需要C#关键字而不是全名,那么我认为您将必须编写自己的转换方法.请参见 C#内置类型的完整列表.


int 不是Type.这是一个别名为System.Int32的C#关键字,即Type.
请考虑以下事实:C#.NET不是唯一的.NET编程语言.在VB.NET(上帝禁止)中, int 毫无意义,甚至更不用说Type.
还请注意不同的自动着色.第一个整数是蓝色(C#,一个关键字),第二个整数是纯色(vb,普通标识符).
因此,您只能得到System.Int32作为答案,因为您的class/程序集可以通过任何 .NET兼容语言使用,而不仅是C#,其中int具有含义. /blockquote>

Hi everyone,I have doubt regarding getting the return types .

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.

解决方案

AFAIK you can''t without coding special case stuff - "int" is just syntactic sugar for Int32.


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.


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.


这篇关于如何在C#中找到返回类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆