c# - Why is that var can only be declared and initialized in a single statement? -


why var can declared , initialized in single statement in c#?

i mean why cannot use:

var x;  x = 100; 

since implicit typed local variable "var" , compiler takes type right of variable assignment operator, why matter should declared , initialized in single statement?

because statement declares variable needs imply type in order compiler know var. sure, person own intuition can logically step through code , determine type will be. compiler isn't complex human intuition. needs type defined in statement in order compile statement logically complete action.

every statement needs individually complete , compilable.


Comments

Popular posts from this blog

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

android - How to create dynamically Fragment pager adapter -

1111. appearing after print sequence - php -