I was wondering if there exists somewhere a collection or list of C# syntax shortcuts. Things as simple omitting the curly braces on if
statements all the way up to things like the ??
coalesce operator.
views:
596answers:
5
A:
I don't know of a precompiled list, but the C# Reference (especially the C# Keywords section) concisely contains the information you're looking for if you're willing to read a bit.
Joren
2009-09-16 22:33:05
+1
A:
How does this C# basic reference pdf document looks to you?
Here's another pdf.
Vadim
2009-09-16 22:34:18
Thanks, I've seen the first one and it has a few examples on there, I was just wondering if there existed a more comprehensive list out there, including some of the not so obvious ones.
Graham
2009-09-16 22:47:58
+1
A:
a = b ? c : d ;
is short for
if (b) a = c; else a = d;
And
int MyProp{get;set;}
is short for
int myVar;
int MyProp{get {return myVar; } set{myVar=value;}}
Also see the code templates in visual studio which allows you to speed coding up.
But note that short code doesn't mean necessarily good code.
codymanix
2009-09-17 00:28:47
+1
A:
My all time favorite is
a = b ?? c;
which translates to
if (b != null) then a = b; else a = c;
mr_dunski
2009-09-17 00:49:39
A:
They are not syntax shortcuts, but snippets are great coding shortcuts. Typing prop (tab)(tab), for example, stubs out the code you need for a property.
http://msdn.microsoft.com/en-us/library/ms165392%28VS.80%29.aspx
HeathenWorld
2009-09-17 01:30:41