Linked Questions
120 questions linked to/from Hidden Features of C#?
123 votes
25 answers
35k views
Hidden features of WPF and XAML?
Here is a large number of hidden features discussed for variety of languages. Now I am curious about some hidden features of XAML and WPF? One I have found is the header click event of a ListView &...
72 votes
43 answers
43k views
Hidden features of Bash
Shell scripts are often used as glue, for automation and simple one-off tasks. What are some of your favorite "hidden" features of the Bash shell/scripting language? One feature per answer Give an ...
227 votes
12 answers
54k views
What are 'closures' in .NET?
What is a closure? Do we have them in .NET? If they do exist in .NET, could you please provide a code snippet (preferably in C#) explaining it?
55 votes
38 answers
36k views
C# Antipatterns
To cut a long story short: I find the Java antipatterns an indispensable resource. For beginners as much as for professionals. I have yet to find something like this for C#. So I'll open up this ...
131 votes
12 answers
155k views
How to make C# switch statement use IgnoreCase?
If I have a switch-case statement where the object in the switch is a string, is it possible to do an IgnoreCase compare? I have for instance: string s = "house"; switch (s) { case "...
169 votes
9 answers
175k views
How to check if an appSettings key exists?
How do I check to see if an Application Setting is available? i.e. app.config <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key ="someKey" ...
91 votes
16 answers
24k views
C# developers learning Java, what are the biggest differences one may overlook? [closed]
For c# developers that are staring out to learn Java, are there any big underlying differences between the two languages that should be pointed out? Maybe some people may assume things to be the same,...
125 votes
13 answers
10k views
How do I check for nulls in an '==' operator overload without infinite recursion?
The following will cause infinite recursion on the == operator overload method Foo foo1 = null; Foo foo2 = new Foo(); Assert.IsFalse(foo1 == foo2); public static bool operator ==(Foo ...
130 votes
5 answers
43k views
What is idiomatic code?
I'd be interested in some before-and-after c# examples, some non-idiomatic vs idiomatic examples. Non-c# examples would be fine as well if they get the idea across. Thanks.
88 votes
7 answers
90k views
Quickest way to enumerate the alphabet
I want to iterate over the alphabet like so: foreach(char c in alphabet) { //do something with letter } Is an array of chars the best way to do this? (feels hacky) Edit: The metric is "least typing ...
106 votes
9 answers
54k views
Upper vs Lower Case
When doing case-insensitive comparisons, is it more efficient to convert the string to upper case or lower case? Does it even matter? It is suggested in this SO post that C# is more efficient with ...
73 votes
8 answers
59k views
Create empty C# event handlers automatically
It is not possible to fire an event in C# that has no handlers attached to it. So before each call it is necessary to check if the event is null. if ( MyEvent != null ) { MyEvent( param1, param2 ); ...
83 votes
6 answers
110k views
Events - naming convention and style
I'm learning about Events / Delegates in C#. Could I ask your opinion on the naming/coding style I've chosen (taken from the Head First C# book)? Am teaching a friend about this tomorrow, and am ...
85 votes
9 answers
13k views
Is there a downside to adding an anonymous empty delegate on event declaration?
I have seen a few mentions of this idiom (including on SO): // Deliberately empty subscriber public event EventHandler AskQuestion = delegate {}; The upside is clear - it avoids the need to check for ...
108 votes
5 answers
11k views
What's the false operator in C# good for?
There are two weird operators in C#: the true operator the false operator If I understand this right these operators can be used in types which I want to use instead of a boolean expression and where ...