How do I move from Java to C#?

Biggest tip: go with the .NET naming conventions from the word go. That way you'll constantly be reminded about which language you're in. (Sounds silly, but it really is helpful.) Embrace the idioms of the language as far as possible.

There are various books specifically for folks in your situation - search for "C# for Java" in Amazon and you'll get plenty of hits. It's worth reading carefully to make sure you don't assume that things will work the same in C# as in Java. (For instance, in C# instance variable initializers are executed before the base class constructor body; in Java they happen after. Subtle things like this can take a while to learn, and are easy to miss if you're skimming.)

If you're going to be using C# 3, I'd get a book which definitely covers that - everything in C# 3 will be new to you. Gratuitous plug: my own book (C# in Depth) covers C# 2 and 3, but assumes you already know C# 1. (In other words, it won't be enough on its own, but you may want it as a "second" book.)


See this great article on C# from a Java Developer's Perspective. It has several insights on the things that can be done in both sides to avoid minimum overhead. Having example in both the language you know and the language you want to learn eases the learning curve quite a bit.


  1. Install Visual Studio 2008 and Resharper with IntelliJ IDEA key bindings. This gives you things like prompting you to include namespaces if you start using them.
  2. Start a new project and start writing Java code, when you run into something that doesn't work properly or it's unable to find the class you're trying to use Google "PrintLn in c#".
  3. Write tests or code snippets for sanity checks, like you may want to check if == works for strings (it does)
  4. realize that c# alias Data Types (int is an alias for System.Int32, string for System.String)
  5. look at other peoples code I recommend JP Boodhoos Google code
  6. Take a job in C#, there's lots of jobs requiring both Java and C# especially in support.
  7. Know your libraries, most Java libraries have been ported and most of the time the name is either like (Hibernate => NHibernate) or (Xstream => Xstream.Net). Not every library has an obvious name so just start looking into random ones you hear about here. ie (Rhino.Mocks,HTMLAgilityPack,MBUnit,Rhino.Commons,Castle Project)
  8. Go to usergroup meetings look for a DNUG (Dot Net User Group) they'll be helpful and you can get some good advice.

There's a cheat-sheet from Microsoft for Java developers using C# :)

Tags:

C#

Java