Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Syntax Shortcuts

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.

like image 400
Graham Conzett Avatar asked Nov 27 '22 15:11

Graham Conzett


1 Answers

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.

like image 60
codymanix Avatar answered Dec 11 '22 18:12

codymanix