Monday, September 19, 2016

no more "predeclaring" out variables, well, unless you want to

This has a bunch of notes on C# 7.0 and it starts out mentioning that you may new up out variables right when you hand them into a method signature as out variables so that this...

int peaches;
int bananas;
blender.MixNMutilate(out peaches, out bananas);
blender.PourOutPaste(peaches, bananas);

 
 

...may now become...

blender.MixNMutilate(out int peaches, out int bananas);
blender.PourOutPaste(peaches, bananas);

 
 

...and you can probably even use var...

blender.MixNMutilate(out var peaches, out var bananas);
blender.PourOutPaste(peaches, bananas);

 
 

...and hand in a wildcard for that thing you don't care about.

blender.MixNMutilate(out var peaches, out *);
blender.PourOutPaste(peaches);

No comments:

Post a Comment