嵌套类.GetType() [英] Nested Class .GetType()

查看:71
本文介绍了嵌套类.GetType()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在弄乱嵌套类并将类型名称输出到控制台窗口时,我注意到了一些好奇.我想知道是否有人可以为我解释一下.在主类上调用GetType()时,它将返回我期望的结果,这是相关名称空间之后的类的名称.即Namespace.Namespace.Classname

I noticed something curious when messing around with nested classes and outputting the name of the type to a console window. I was wondering if someone could explain it a bit for me. When calling GetType() on the main class, it returns what I would expect, which was the name of the class after the relevant namespaces. i.e. Namespace.Namespace.Classname

但是,当我从封闭类中调用函数以返回嵌套类的类型时,我得到的返回值是这样的:

However, when I call a function from within the enclosing class to return the type of the nested class I get the value returned as this:

Namespace.Namespace.ClassNameEnclosing + ClassNameNested.

为什么它不简单地以点表示法返回.为什么用+符号?我只是对导致这种表示法的背景中发生的事情感到好奇.

Why is it not simply returned as dot notation. Why the + symbol? I am just curious as to what is going on in the background that causes this notation.

推荐答案

点用于表示名称空间.嵌套的类仍位于相同的名称空间中,只是嵌套在一个类中.

Dots are used to denote namespaces. The nested class is still in the same namespace, it's just nested within a class.

从ECMA-335的简短研究中,我不能立即得出结论,在IL中,包含点的不合格类型名称实际上是否有效;我怀疑会,但是它将使各种诊断难以阅读.

I can't tell offhand (from a brief study of ECMA-335) whether an unqualified type name which included a dot would actually be valid in IL; I suspect it would, but it would make all kinds of diagnostics harder to read.

这篇关于嵌套类.GetType()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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