This came to my mind after I learned the following from this question:
where T : struct
We, C# developers, all know the basics of C#. I mean declarations, conditionals, loops, operators, etc.
Some of us even mastered the stuff like Generics, anonymous types, lambdas, LINQ, ...
But what are the most hidden features or tricks of C# that even C# fans, addicts, experts barely know?
yield
by Michael Stumvar
by Michael Stumusing()
statement by kokosreadonly
by kokosas
by Mike Stoneas
/ is
by Ed Swangrenas
/ is
(improved) by Rocketpantsdefault
by deathofratsglobal::
by pzycomanusing()
blocks by AlexCusevolatile
by Jakub Šturcextern alias
by Jakub ŠturcDefaultValueAttribute
by Michael StumObsoleteAttribute
by DannySmurfDebuggerDisplayAttribute
by StuDebuggerBrowsable
and DebuggerStepThrough
by bdukesThreadStaticAttribute
by marxidadFlagsAttribute
by Martin ClarkeConditionalAttribute
by AndrewBurns??
(coalesce nulls) operator by kokoswhere T:new
by Lars Mæhlumenum
values by lfoustevent
operators by marxidad?:
) by JasonSchecked
and unchecked
operators by Binoj Antonyimplicit and explicit
operators by Flory__makeref __reftype __refvalue
by Judah Himangopartial
methods by Jon EricksonDEBUG
pre-processor directive by Robert Durgin__arglist
by Zac BowlingTransactionScope
by KiwiBastardDependantTransaction
by KiwiBastardNullable<T>
by IainMHMutex
by DiagoSystem.IO.Path
by ageektrappedWeakReference
by Juan ManuelString.IsNullOrEmpty()
method by KiwiBastardList.ForEach()
method by KiwiBastardBeginInvoke()
, EndInvoke()
methods by Will DeanNullable<T>.HasValue
and Nullable<T>.Value
properties by RismoGetValueOrDefault
method by John SheehanThis isn't C# per se, but I haven't seen anyone who really uses System.IO.Path.Combine()
to the extent that they should. In fact, the whole Path class is really useful, but no one uses it!
I'm willing to bet that every production app has the following code, even though it shouldn't:
string path = dir + "\\" + fileName;