System.Type对象有什么特别之处?什么是方法组名? [英] What is special about the System.Type objects? And what are method group names?

查看:89
本文介绍了System.Type对象有什么特别之处?什么是方法组名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我正在阅读C#Docs并且我遇到了这样的句子:"虽然命名空间名称被归类为表达式,但它不会计算为值,因此永远不会是任何表达式的最终结果。您不能将名称空间
名称传递给方法参数,也不能在新表达式中使用它,或将其分配给变量。您只能将其用作较大表达式中的子表达式。类型(与System.Type对象不同),方法组名称(与特定的
方法不同)" 

Hello. I'm reading the C# Docs and I've encountered this sentence: "although a namespace name is classified as an expression, it does not evaluate to a value and therefore can never be the final result of any expression. You cannot pass a namespace name to a method parameter, or use it in a new expression, or assign it to a variable. You can only use it as a sub-expression in a larger expression. The same is true for types (as distinct from System.Type objects), method group names (as distinct from specific methods)" 

"对于类型(与System.Type对象不同),情况也是如此。这究竟意味着什么?你能用System.Type显示这个例子吗?它与反射有关吗?对吗? 

"The same is true for types (as distinct from System.Type objects)" What does that exactly mean? Can you show example of this with the System.Type? It has something to do with the Reflection? right? 

还有什么是方法组名称和具体方法? 

Also what are method group names and specific methods? 

推荐答案

是  System.Type 与反思有关并且 保存类型的元数据。您可以获得一个
的实例 使用 typeof()  将类名作为输入的方法如下:

Yes the System.Typeis related to Reflection and  holds the meta data of type. You can get an instance of it  using thetypeof()  method which would take the class name as input like:

public class Program
{
   public  static void Main(String[] args)
   {
     Type type = typeof(Program);
   }
}

我们还可以获得 这是 在C#中的任何对象上使用 GetType()方法的实例如:

and we can also get  it's  instance using the GetType() method on any object in C# like:

public class Program
{
   public  static void Main(String[] args)
   {
     Type type = this.GetType();
     Type argsType = args.GetType();
   }
}

和 对于方法组:

and  for method group:

方法组是一组方法的名称(可能只是一个) - 即理论上
ToString 方法可能有多个重载(加上任何扩展方法):
ToString() ToString(字符串格式)等 - 因此
ToString 本身就是一个"方法组"

A method group is the name for a set of methods (that might be just one) - i.e. in theory the ToString method may have multiple overloads (plus any extension methods): ToString(), ToString(string format), etc - hence ToString by itself is a "method group".

For 更多细节,请参阅 以下 发布:

For  more details, refer to the  following  post:

什么是Methood集团在C#?

希望 它 有帮助!

Hope  it  helps!


这篇关于System.Type对象有什么特别之处?什么是方法组名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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