C# expression evaluates to a namespace

c#, expression

Solution

This is how the grammar is defined. Look at:

System.String

is an expression containing a dot operator that operates on a couple different expressions. `System` alone is considered an expression. An expression can be as simple as a single identifier or literal (hint: it's defined recursively.)

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.

Not being able to use it as, say, an argument to a method doesn't disqualify it as being considered an expression.

Problem

MSDN docs state "An expression is a fragment of code that can be evaluated to a single value, object, method, or namespace." Could someone please explain what it means for an expression to evaluate to a namespace - how can that be? edit: fixed typo

Original source