Type-inferring a constant in C#

后端 未结 11 1171
花落未央
花落未央 2020-12-05 13:14

In C#, the following type-inference works:

var s = \"abcd\";

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

T

11条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-05 13:31

    Interesting. I don't know if it is just a limitation of the C# compiler or if it a fundemental limitaion of the language itself.

    To explain what I mean, consider VB.

    In VB 9 you also couldn't infer constants, but this was just a limitation of the compiler. In VB 10 they were able to add constant type inference without making any significant changes the to language.

提交回复
热议问题