How do I move from Java to C#?

前端 未结 9 1189
花落未央
花落未央 2020-12-23 12:03

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

相关标签:
9条回答
  • 2020-12-23 12:06

    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.

    0 讨论(0)
  • 2020-12-23 12:09

    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.

    0 讨论(0)
  • 2020-12-23 12:13
    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.
    0 讨论(0)
  • 2020-12-23 12:15

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

    0 讨论(0)
  • 2020-12-23 12:23

    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.

    0 讨论(0)
  • 2020-12-23 12:24

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

    0 讨论(0)
提交回复
热议问题