tags:

views:

644

answers:

10

I know Java well. Which caveats and resources will help me cross to the other side (C#) as painlessly as possible.

+15  A: 

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.)

Jon Skeet
C# in Depth was a good read according someone who isn't the author, too (IE me!). Though I have to confess that I think the cover art is kinda' ugly.
Greg D
It's less ugly than it would have been with a picture of me there :)
Jon Skeet
+6  A: 

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.

smink
A: 

The language syntax is vary similar, so I should only read a small reference of the C# syntax. Like a simple book (for experienced programmers) or maybe wikipedia (http://en.wikipedia.org/wiki/Comparison_of_Java_and_C_Sharp) will tell enough.

The biggest difference is the library: Asp.Net websites are totally different from java servlets.

Don't read much, just start programming!

Paco
DO NOT use the old and busted ASP.NET web forms model. Skip it for ASP.NET MVC. Much better framework.
Will
The languages *were* very similar, particularly Java 1.4 vs C# 1. These days they're really quite different, and even where they *look* similar (e.g. generics) they can be worlds apart.
Jon Skeet
Believing the two languages to be similar is a great way to find yourself in a world of pain... this can easily lead to overlooking subtle differences such as how you rethrow an exception.
James Schek
+4  A: 

This has been covered in-depth already I believe. See the following threads.

I don't wanna close it though because it doesn't seem to be an 'exact' duplicate, and I like Jon's answer to this question.

jjnguy
A: 

Here's a link that has syntax comparison between Java and C# (even though it's almost identical, there are a few differences).

http://www.harding.edu/fmccown/java1_5_csharp_comparison.html

A: 
  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 its unable to find the class your 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.
Scott Cowan
A: 

Start coding in C#.

Done!

JDrago
A: 

Use Sharpen to convert your Java programs to C# and see the differences.

axelclk
A: 

I know that a good answer has already been accepted. However, I'd like to make an addition...

I find that learning a new language typically involves learning subtle syntactic differences....especially when dealing with the difference between languages in the C/C++/Java/C# family.

In addition to a nice thick reference book I recommend getting a pocket reference like C# 3 Pocket Reference from O'Reilly. It won't help you with the design patterns etc...but will provide a very quick reference about the specific differences of the language you are using.

Here's a quick blurb about this book from that site:

C# 3.0 Pocket Reference includes plenty of illustrations and code examples to explain:

  • Features new to C# 3.0, such as lambda expressions, anonymous types, automatic properties, and more
  • All aspects of C# syntax, predefined types, expressions, and operators
  • Creating classes, structs, delegates and events, enums, generics and constraints, exception handling, and iterators
  • The subtleties of boxing, operating overloading, delegate covariance, extension method resolution, interface reimplementation, nullable types, and operating lifting
  • LINQ, starting with the principles of sequences, deferred execution and standard query operators, and finishing with a complete reference to query syntax-including multiple generators, joining, grouping, and query continuations
  • Consuming, writing, and reflecting on custom attributes

I used this book (well the original) to help me go from being a Java to a C# developer. While I was learning, I kept it by my desk at all times and it really helped.

mezoid
A: 

I made the transition pretty easily by using C# at work, but one of the most important things to do is familiarize yourself with the .NET API and some of the powerful techniques available in C#.

After I learned the .net library I relied on it a lot more than I used to, so learning about the things it can do for you is very helpful. After that, if you work with db code at all, learn LINQ, and also techniques lambas, anonymous types and delegates are also a useful to pick up.

Tony Peterson