Why doesn't C# allow for global inferred types i.e. using var?
Posted
by BritishDeveloper
on Stack Overflow
See other posts from Stack Overflow
or by BritishDeveloper
Published on 2010-04-08T08:58:36Z
Indexed on
2010/04/08
9:03 UTC
Read the original article
Hit count: 242
I know it can't be done since using var can only be done for local variables. I'm just wondering if anyone has a theory why the C# team thought this should be so. e.g. what would be wrong with this:
public class SomeClass
{
var someString = "hello"; //not cool
public SomeClass()
{
var someOtherString = "hello"; //cool
}
}
If someString
is initialised then it is obviously a string just like someOtherString
. Why is there one rule for local variables and another for globals?
© Stack Overflow or respective owner