Every time you write a blog, the first sentence is this: the programmer is very hard, in addition to writing procedures, but also to write a blog! Of course, hope that the future day, a boss see this blog, to your programmer staff pay bar! Because the programmer's world is silent except bitter force. Most of the programmers in my eyes do not love to talk, silently bear the great pressure of programming, in addition to technical exchanges, they do not want to be good at communicating with others, more reluctant to anyone into their hearts, they often a person home!
More gossip, let's get to the point:
First of all, let's explain the anonymous variable, before I explain the anonymous variable, I'll show the declaration of the anonymous variable by code as follows:
Static voidMain () {varA =1;//here, A is parsed into the int type and int a=1; varAA ="";//AA will be parsed into string type and string Aa= ""; varAAA =New[] {1,2,3,4,5};//AAA will be parsed into an array of type int and int[] type is exactly the same drop varB =New{ };//B is parsed into an empty object/collection, with no attributes and object b=new {}; varBB =New{UserName ="Jack.chen", Sex ="male", age = -, Address ="China-Suzhou"};//The BB will be parsed into an object with properties and the Preson type is exactly the same. varBBB =New[] {NewPreson {UserName ="Jack.chen", Sex ="male", age = -, Address ="China-Suzhou"},NewPreson {UserName ="Loose-li", Sex ="female", age = -, Address ="China-Shanghai"},NewPreson {UserName ="Cathy", Sex ="female"} };//The BBB will be parsed into a Preson object set and the list<person> type is exactly the same}
classPreson {stringUserName; Public stringUserName {Get{returnUserName;} Set{UserName =value;} } stringsex; Public stringSex {Get{returnSex;} Set{Sex =value;} } intAge ; Public intAge {Get{returnAge ;} Set{age =value;} } stringaddress; Public stringAddress {Get{returnAddress;} Set{Address =value;} } }
Each line of code above is exactly the same as the comment that follows each line of code
That is, when declaring a variable (and assigning it at the same time), you do not have to specify the type of the variable at all, as long as a VAR solves the problem.
Of course, some people will ask: does this definition degrade the performance of the program?
Can be responsible to tell you that this writing will not affect performance!
The above code and the code in the comments, the generated IL code (intermediate Language code) is exactly the same (the compiler based on the value of the variable, the derivation of the type of the variable, the resulting IL code)
On C # Anonymous variables and anonymous methods