Friday, 30 August 2013

How many syntactic sugar is in C# [on hold]

How many syntactic sugar is in C# [on hold]

Syntactic sugar is syntax within a programming language that is designed
to make things easier to read or to express. It makes the language
"sweeter" for human use: things can be expressed more clearly, more
concisely, or in an alternative style that some may prefer. - wikipedia
In C# how many syntactic sugar are there, which we can use to improve code?
What I know is:
Properties, to replace getter and setter methods.
?? operator, to replace v = (value != null) ? value : value2, also it
could be used like this: var result = value1 ?? value2 ?? value3 ?? value4
?? defaultValue; to get first non-null value.
Lambda expression, to define a anonymous method like Func<string,int>
returnLength = (text) => { return text.Length; };
var keyword.
init collections in-line, var names = new List<string> {"Mary", "Tom"};
Any more?

No comments:

Post a Comment