Type-inferring a constant in C#

Posted by Andreas Grech on Stack Overflow See other posts from Stack Overflow or by Andreas Grech
Published on 2010-01-24T19:33:35Z Indexed on 2010/04/10 19:23 UTC
Read the original article Hit count: 282

Filed under:
|
|

In C#, the following type-inference works:

var s = "abcd";

But why can't the type be inferred when the variable is a constant?

The following throws a compile-time exception:

const var s = "abcd"; // <= Compile time error: 
                      //    Implicitly-typed local variables cannot be constant

© Stack Overflow or respective owner

Related posts about c#

Related posts about type-inference