MSDN 文档声明“表达式是可以计算为单个值、对象、方法或命名空间的代码片段。”
谁能解释一下表达式求值到命名空间的含义 - 这怎么可能?
编辑:修复错字
最佳答案
语法是这样定义的。看看:
System.String
是一个包含点运算符的表达式,该运算符对几个不同的表达式进行运算。 System
单独被认为是一个表达式。表达式可以像单个标识符或文字一样简单(提示:它是递归定义的。)
Expressions (C# 3.5 spec section §7.1: Expression classifications)
An expression is classified as one of the following:
...
A namespace. An expression with this classification can only appear as the left hand side of a member-access (§7.5.4). In any other context, an expression classified as a namespace causes a compile-time error.
不能将它用作方法的参数,这并不意味着它不能被视为表达式。
关于C# 表达式计算为命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1303131/