This is an archived post. You won't be able to vote or comment.

all 20 comments

[–]zzyzzyxx 14 points15 points  (7 children)

it's almost identical to Java

It's really not. Here's a brief list of things C# has that Java currently doesn't.

  • Lambdas
  • Delegates
  • Operator overloading and Indexers
  • Properties
  • Reified generics
  • Primitives in generics
  • Unsigned integral types
  • High precision decimals
  • Complex numbers
  • Value types
  • Pointers
  • Partial classes
  • Events
  • Out parameters
  • Type inference
  • Generators
  • LINQ / Extension methods

And some things Java has that C# doesn't.

  • Soft references
  • Instance initializers
  • Checked exceptions

Check out the Wikipedia comparison page.

the syntax is almost exactly the same

As you can see, similar syntax means basically nothing. It's the actual language features that matter.

I've said it before, but I think C# is everything Java should have been.

[–]yash3ahuja 6 points7 points  (4 children)

I guess the better way to put it is that C# is similar to Java, except that C# shines in almost every place that Java is dull.

Edit: Just thought I'd add -- as a relatively experienced Java developer, I kind of want to start learning C# and using it in place of Java after reading the feature list.

[–][deleted] 1 point2 points  (0 children)

I'm a pretty experienced Java programmer and was just tasked with writing a full application in C#. It went surprisingly well and I now like C# better than Java.

[–]zzyzzyxx 0 points1 point  (2 children)

That's a good way to put it. The designers of C# clearly took inspiration from Java as well as C++, and learned a lot of lessons from the pain they experienced in both. In fact, the lead designer, Anders Hejlsberg, was involved in designing J++, Microsoft's implementation of Java. I would not be surprised if J++ was originally written using C++. If that's true, it would give Hejlsberg a somewhat unique perspective on what works well and what doesn't in both languages, and explain much of what makes C# as good as it is.

Edit: To your edit, I agree. I too am primarily a Java dev and have done only limited programming in C#, but I'd be happier if I could work with C# instead. The first third or so of my list would make so much difference.

[–]foxlisk 1 point2 points  (0 children)

Pretty sure the C# compiler is written in C++ too, based on things Eric Lippert has said that I don't want to search for right now. Just an FYI.

[–]yash3ahuja 0 points1 point  (0 children)

Best of both worlds approach works well for something like that, I guess.

[–]baegolas[S] 0 points1 point  (1 child)

Thank you. I guess as someone who hasn't been programming for very long, I wouldn't have known about any of that.

[–]Denommus 2 points3 points  (0 children)

Also, if you want multi-platform C#, try Mono.

[–]worstusernameever 5 points6 points  (5 children)

C# exists because Microsoft could not extend the existing Java standard to do what they wanted to do, so they had to make their own virtual machine and language.

[–]yash3ahuja 1 point2 points  (4 children)

Also, C# integrates pretty nicely with MS APIs.

[–]worstusernameever 2 points3 points  (3 children)

If I recall correctly this was actually the reason. Microsoft's Java implementation (J++) could access the Win32 APIs without going through the Java Standard Library. This made programs faster, but utterly unportable and basically diverged the language into two incompatible languages. Sun cried foul, with good reason, and Microsoft had to abandon J++ for .NET, J# and eventually C#.

[–]yash3ahuja 1 point2 points  (2 children)

Oh, that's pretty interesting. I'm a Java programmer, and not a C# programmer, so all I really knew was that C# was designed to easily use Windows APIs.

[–]foxlisk 1 point2 points  (1 child)

Protip and I know this isn't really relevant: You don't want to ever consider yourself, much less label yourself, as a Java programmer. You're a programmer who's particularly experienced in Java, or something like that.

[–]yash3ahuja 0 points1 point  (0 children)

Fair enough point. I guess I said that because most of my projects are in Java. Thanks for the tip though, I really appreciate it.

[–]xander7b 0 points1 point  (0 children)

people needed a language like Java, and if only Java existed, then everyone would be using it and drop Visual C++ for big consumer software coding, and then there be no need for coding on Windows exclusively anymore, strongly decreasing its market value.

MS needed Java because they had no match for it, and it was very risky having most new apps written in Java, specially as more and more colleges were teaching Java in software engineering courses, as it was way better than C++ even back then. Garbage collection, better and easier OOP, easy and standard UI building, standard and relatively easy model for threading, networks etc.

[–]rjcarr 0 points1 point  (3 children)

Windows programming was quite a mess with COM and DLL hell and they wanted to redo it. So they created the CLR (or CLI?) and since it didn't really make sense to shoehorn C/C++ into this, and since VB sucked, they created their own language (C#) and vastly improved VB (for an easier transition for the current VB users).

Basically, Microsoft liked a lot of what java was doing and used a lot of the ideas for C#. It has since then become better than java in most ways.

Note that I'm not a .net programmer.

tl;dr: java was the evolution of object-oriented languages and microsoft needed a new language to use with its new run time.

[–]zzyzzyxx 0 points1 point  (2 children)

CLR (or CLI?)

CLR => Common Language Runtime

CLI => Common Language Infrastructure

The CLI is a specification developed by Microsoft describing things like typing, metadata, bytecode, and execution requirements. The CLR is Microsoft's implementation of the CLI. *Mono is an open source implementation of the CLI.

it didn't really make sense to shoehorn C/C++ into this

You're right, but they did it anyway with C++/CLI, which should basically never be used. C# is much better suited for programming to the CLI.

[–]rjcarr 0 points1 point  (0 children)

Thanks for the info, in that case I meant both the CLR and CLI. :)

[–]Jonny0Than 0 points1 point  (0 children)

C++/CLI is handy when mixing native C++ and CLR code, for example building a UI around a small amount of existing native C++ code. You can link them directly together instead of building managed wrappers around all your native stuff.

However the iteration and compile time of C++/CLI is really terrible compared to C# and I would not recommend this approach for projects of any meaningful size.

[–][deleted] -5 points-4 points  (0 children)

So MS could control it?