As a response to this thread:


What are the things C# got right?

Please don't list the things C# did wrong, just right.

+8  A: 

case sensitivity

Kyle West
case sensitivity by default is needed for string literals/comparisons, but for the language itself I really like a _case_aware_ approach, where it's not case sensitive, but the ide does know and correct when you use a different case from the declaration.
Joel Coehoorn
I think case sensitivity is stupid. I'm with Joel … and I actually think that VB is doing it right, even though proper casing all their keywords might not be en vogue any more.
Konrad Rudolph
No, even in VB, you force developers to always use the same casing as used in the definition, making VB de facto a case-sensitive language. Compiler should, however, be smart enough to recognize casing errors and suggest correct spellings.
I like case sensitivity in a language. If I have a property Foo and a method which takes an argument foo, I want to be able to write Foo = foo.
Ed Swangren
In no way is VB case sensitive. Sure VS IDE will change your casing to match a previous declaration, which is a good thing, if you edit source in say notepad you can have different casing and the compiler will not complain. Finally unlike C# in VB your can't have a field named fred and property named Fred.
Tim Murphy
+10  A: 

Garbage collection, although you could say that is a .NET thing.

+16  A: 

Generics and garbage collection

Troy J. Farrell
+13  A: 

lambda expressions

+6  A: 

Not specifically C# - Visual Studio :)

+7  A: 

LINQ syntax

Richard Ev
+4  A: 

Structs, pointers (especially "pinning"), delegates, generics, assemblies, AppDomains, garbage collection, namespaces.

So that it doesn't look like mere fawning praise, here are a few things deliberately excluded from the list (though, in keeping with the spirit of the question, I won't elaborate on them):

finalization, coroutines (the "yield" keyword), collections API, platform neutrality

I have yet to use the yield keyword...nor really understand how/when it is useful.
Richard Ev
If you ever wrote your own collection classes in .NET 1.0, and then again in .NET 2.0, you'd understand why "yield" is awesome. I'd like to know why it was excluded.
Joel Mueller
Yield is fantastic, and very handy. I left it out of my list of things that C# "got right" because they don't implement full coroutines.
What do you think is missing from yield return re: coroutines?
Daniel Earwicker
+7  A: 

IDisposable/using pattern, null coelescing operator (??), extension methods

Matt Briggs
No way, they didn't get the null coalescing operator right! If they had, you could do this: int value = someObject.Value ?? 5; // coalesces to 5 if someObject is null
That would indeed be handy... But null propagation is not that simple.
@mquander: is there any language that does that? I'm happy with int? i = null; k = i ?? 0;
Matt Briggs
@Matt - not that I know of, but it would sure be really, really convenient, and I don't know why it would be difficult or confusing to implement.
@mquander: You can almost do that with nullable types. int? foo = null; int bar = foo ?? 5;
Joel Mueller
Sorry, I misread. You wanted it to work when someObject is null, not when someObject.Value is null.
Joel Mueller
@Matt Briggs - Delphi has an operator to do that. You can write it as a generic method in C#, google for IfNotNull.
Daniel Earwicker
IDisposable sucks, using makes it suck less (all the alternatives also suck of course)
+3  A: 

I really like MethodInvoke for coordinating threads to the main threads for updates (although this may be a .NET thing). Thread coordination in C/C++ was such a spectacular pain...

Also, just the whole thread starting and running syntax, with delegates, is just extremely useful.

+38  A: 

Let's see,

  • Properties (basically standardization of get/set pair methods at framework level)
  • Same for Events
  • Only explicit fallthrough on case statements allowed ( a serious source of bugs in C/C++)
  • The using statement
  • Expression<Func<>> ... allows code to be reinterpreted at runtime, making Linq 2 SQL possible.
  • Iterators (using yield to build state machine iterators automatically by the compiler)
  • Operator overloading. Only safe overloading allowed ( <= is computed automatically from < and == and complementary operators must always be defined)
  • Lambda syntax, (I like e => e + 1, more than in most languages).
  • explicit overriding of virtual functions using override.
  • Extension methods :)
  • The Linq pattern ( Linq to anything ) ...
Pop Catalin
I did not know that C# only allowed explicit fallthrough on case statements. Nice!
Gary Willoughby
and [Attributes]
upvote for 'using' statement
Joel Coehoorn
By "explicit fall-through", do you mean by using GOTO? You cannot fall through in C# switch statements at all, although you can fall through empty cases, which is a bit odd but useful nonetheless.
Ed Swangren
Yes by explicit fall through I mean goto, but more it would be more accurate to say no fall-through allowed (except on empty cases).
Pop Catalin
Didn't know the explict fall through either :)
+9  A: 


+8  A: 


+11  A: 

using statement

Oscar Cabrero
+13  A: 

C# got standardized by ISO (ISO/IEC 23270) and ECMA (ECMA-334).

+10 if I could!
Who cares about standardization? You think you're going to be seeing any competing versions (aside from the crippled mono) out there? Bahahahah
+6  A: 
  • Automatic properties.
  • Classes
Joan Venge
+3  A: 


+4  A: 

Having been stuck developing in J2ME lately after my whole career in C#: Properties and delegates/events.


Does the C# stdlib count? Their regexp engine is (surprisingly, to me) one of the best I've seen. In particular, it supports arbitrary lookbehind (rare), and a MatchEvaluator delegate. Short of just giving me the parse tree (like CL-PPCRE), this is about as sweet as they come.

wouldn't this be the .net framework and not c#?
Brian Surowiec
+3  A: 

Optional parameters in C# 4.0 will be pretty awesome too.

+16  A: 

@"unescaped strings" (especially when used with regex. "\\s*\\d.\\d" or @"\s\d.\d"?)

+5  A: 

Eliminating .h files!

Tom Bushell
+2  A: 

It's hard to stay away from wonders of .NET Framework when answering such questions.

It's also hard to avoid repeating "LINQ" and "Lambda Expressions" over and over which are almost the coolest improvements done on a mainstream programming language.

I like the naming conventions, especially Microsoft's extra effort to kill ugly Hungarian prefixes like "m_" from MFC people. I believe code looks cleaner and less cluttered, making it much easier to read.

The "using() { }" method to hint compiler about an object's lifetime is also cool.

+3  A: 

C-style syntax. Clean, efficient, and understandable.

Zach Johnson
+2  A: 

Aside from language features already mentioned, it was the people. Anders Hejlsberg at the helm. The whole C# and .NET Framework team for that matter. Community interaction was very important as well. C# was developed at the right time. Java was little too early, perhaps, but C# benefited from the huge growth of the internet in a time when blogs just started exploding in the developer space, and Microsoft payed attention and communicated a lot with the developer community. They wooed students, universities and colleges, threw free or cheap training events everywhere, and made the .NET Framework something that goes end-to-end from embedded systems (.NET Micro Framework) to desktop to server to database. They made tools and frameworks around .NET for the enterprise, and even put out XNA for XBox development. Plus everything tries to play nice with whatever language you'd like, or have to integrate with.

Richard Hein

Compiling to the CIL/CLR infrastructure, and as a result:

  • looking like normal .exe/.dll from the outside.
  • interoperating with a number of other CLR languages transparently
  • verifiability (safe vs unsafe)
  • emitting chunks of compiled code that is as portable as C# itself
  • being able to concentrate on creating an awesome language

and certainly tons more.

+2  A: 

I move between Java/C++/C# a lot and outside of the many nice syntactic sugary elements of C# I think the best thing they got 'right' was the ability to use runtime reflection on generics.

Java really mucked up with Type Erasure in this respect.

Adrian Regan

Probably more .Net in general but ...

Pure simplicity ... whole experience of being a developer is forced in to pink and fluffy chill out mode by default :)


It's silly little things like no "Push" and "Pop" methods for working with collections. "Add" and "Remove" completely make more sense to me.

It thinks the way I do :)

But also "MSIL" ... need i say more :)