C # Syntax Shortcuts

I was wondering if somewhere there is a collection or list of C # syntax shortcuts. Things like simple, dropping curly brackets on operators ifright down to things like the ??coalesce operator .

+3
source share
6 answers
a = b ? c : d ;

not suitable for

if (b) a = c; else a = d;

and

int MyProp{get;set;}

not suitable for

int myVar;
int MyProp{get {return myVar; } set{myVar=value;}}

Also see code templates in visual studio for faster coding.

But note that short code does not mean that it is good code.

+10
source

My favorite time

a = b ?? c;

which translates to

if (b != null) then a = b; else a = c;
+10
source

# 6.0 . ?. ? ( ) - .

var value = obj != null ? obj.property : null;

var value = obj?.property

var value = list != null ? list[0] : null;

var value = list?[0]
+4
+1

I don't know the pre-compiled list, but the C # Reference (especially the C # Keywords section) briefly contains information if you want to read a little.

0
source

They are not syntax labels, but fragments are great labels for encoding. For example, enter a tab (tab) (tab) to mute the code required for the property.

http://msdn.microsoft.com/en-us/library/ms165392(VS.80).aspx

0
source

Source: https://habr.com/ru/post/1717882/


All Articles