Is there reason why you can't declare a static variable within a C# method? -
i've been working in c past couple of years , i've managed use putting single-purpose, static
variables near used within code.
while writing basic method in need of method-scope static value, bit surprised find compiler didn't tried define static object within method.
googling has verified isn't possible within c#. still, i'm curious why code, following, off limits.
public int incrementcounterandreturn() { static int = 0; return ++i; }
granted, simplistic example redefined same affect that's beside point. method-scope, static values have place , purpose. design decisions have prevented such implementation of static objects within c#?
we're on c# version 5.0 , it's 2013. can assume isn't possible because of design choice , not because "that's complex , hard stuff implement." have insider information?
the language design team not required provide reason not implement feature. rather, person wants feature required make case feature best possible way design, implementation, test, , education teams can spending budgets. no 1 has ever done proposed feature.
were still on design team , had feature pitched point out unnecessary. feature in c known cause of developer confusion, particularly novices, , benefit of local vs type scope tiny.
Comments
Post a Comment