c# - Why double declaration is needed while defining variable Types? -


i newbie c#, , 1 thing cant understand @ moment, why types needs written twice, i.e.

dictionary<string, string> lines = new dictionary<string, string>(); 

why couldnt simpler, like:

lines= new dictionary<string, string>(); // or dictionary<string, string> lines = (); 

doesnt "lines" variable? have been easier.

if code inside method, why the var keyword has existed since c# 3.0:

var lines = new dictionary<string, string>(); 

if in class declaration, can't use var keyword. admit not knowing specifics of why implicit typing isn't permitted @ class level, suffice isn't. explicit typing required:

private dictionary<string, string> lines; 

completely separate declaration initialization of variable. can done on same line, or in constructor, or in method, etc. new keyword going need explicitly told type:

new dictionary<string, string>() 

these 2 different things both require type specified own discrete , reasons.

ultimately, time ask "why doesn't language this?" should really asking "should language this? necessary?"

as eric lippert once said me in previous question: "by eliminating [that unnecessary feature], none of rules [that unnecessary feature] needed though of, argued about, designed, specified, implemented, tested, documented, shipped customers, or made compatible every future feature of c#."

it's easy shout bleachers. it's less easy design , support major programming language. maybe 1 day feature exist, , you're welcome propose team. "why doesn't exist", team never made happen.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -