C#:具有“+”在类名中? [英] C# : having a "+" in the class name?
问题描述
类名:MyAssembly.MyClass + MyOtherClass
class name: MyAssembly.MyClass+MyOtherClass
问题显然是+作为分隔符,而不是传统的点,其功能,如果其他分隔符存在
The problem is obviously the + as separator, instead of traditionnal dot, its function, and to find official documentation to see if others separators exist
提前感谢!
推荐答案
只是表示嵌套类型的方式。例如:
That's just the way that a nested type is represented. So for example:
namespace Foo
{
class Outer
{
class Nested {}
}
}
将创建一个类型为full在编译的代码中的 Foo.Outer + Nested
的名称。 (这就是 typeof(Outer.Nested).FullName
会返回,例如。)
will create a type with a full name of Foo.Outer+Nested
in the compiled code. (So that's what typeof(Outer.Nested).FullName
would return, for example.)
对我来说,这是否是指定的行为,或只是微软的C#编译器选择使用;它是一个不可言说的名称,你不能在正常的C#中显式声明一个带有+的类,所以编译器知道它不会与任何其他冲突。
It's not clear to me whether this is specified behaviour, or just what the Microsoft C# compiler chooses to use; it's an "unspeakable" name in that you couldn't explicitly declare a class with a + in it in normal C#, so the compiler knows it won't clash with anything else. Section 10.3.8 of the C# 3 spec doesn't dictate the compiled name as far as I can see.
编辑:我刚刚看到, Type.AssemblyQualifiedName
指定+用于嵌套类型名称之前...但仍然不清楚是否实际需要 或仅仅是常规。
I've just seen that Type.AssemblyQualifiedName
specifies that "+" is used to precede a nested type name... but it's still not clear whether or not that's actually required or just conventional.
这篇关于C#:具有“+”在类名中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!