Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Ok, I want to learn C# for a job interview (they want C# or Java, I know Java, but figure knowing both would be good). I already know Java, C++, C, F# and to some extent Python and Pascal.

What are the big differences between C# and Java or C++? What are some good resources to look into, given I want to get a basic understanding in couple of hours?

BTW: I told them that I didn't know C#, saying that I did however know these other languages, and that I could probably pick it up quite quickly.

share|improve this question

migrated from stackoverflow.com May 21 '11 at 7:41

This question came from our site for professional and enthusiast programmers.

21  
It is better to say that you don't know it than assure you do and fail on some trivial question. Honesty - is the best start of business relationships. –  zerkms May 20 '11 at 2:37
    
@zerkms, very good advice! =) –  MikeU May 20 '11 at 2:39
    
@MBU: It would be better if it was written with proper english ))) I see it looks lame, but cannot write the same thoughts in better way. –  zerkms May 20 '11 at 2:40
1  
I assume you have about 3 days or there about until the interview. If yes, are not going to learn enough in that time to make a difference. Even if you do, what would you do if they ask you what C# projects you have worked on? Anyone can work on a language but those that have used it in production code can talk about it in interviews. I recommend that you be honest with them as zerkms said. To better your odds, focus on your ability to learn quickly and your passion for languages. –  Phil May 20 '11 at 2:58
    
For closure, I got the job, and they are calling me a "Java developer". The interviewer had forgotten in his question sheet, and so for the explict technical questions (after chatting abit about F#) asked me a couple of questions about programming, avoiding any C# syntax ones since he knew I didn't know it. He hadn't used java in about 6 years, and ended up asking me what is a delegate something which C# has and java doesn't. I suggested possibly and inner class used to delegate some tasks to, and he explained it was like a C function pointer. i was: F# is made of those - continations. –  Oxinabox Jun 20 '11 at 10:29
add comment

3 Answers

up vote 4 down vote accepted

Since you know F#, another .NET language, you are in a good position for understanding some of the big difference between C# and Java. I know all three languages so I think I can give you a good list of the big differences between C# and Java:

  • C# generics are reified, whereas Java generics are implemented via erasure.
  • C# has a unified object system with extendable ValueTypes (structs) which have copy semantics and may be allocated on the call stack instead of the heap. Java has a fixed set of primitive value types outside of the object hierarchy.
  • C# has delegates supporting first class functions and anonymous lambda expressions including closures. Java may emulate these using anonymous inner classes.
  • C# has built-in "properties" (use them like fields, but with custom get:unit -> 'a and set:'a -> unit implementations given in type definition) including custom index access implementations, Java doesn't.
  • C# has the static dynamic type, which allows you to program against the DLR with syntax which resolves calls at runtime. Java has no analog.
  • C# doesn't enforce class-per-file like Java does. In fact, C# has "partial classes", which allow you to break a class implementation across files (it even has something called "partial methods" which are similar for methods, but I've never used them).
  • C# and .NET in general are not shy about implementing features which are tied to Windows, such as easier native interop and libraries like WinForms which is just a thin wrapper around GDI+. Java takes pains to remain platform agnostic with libraries like Swing which allows you to make GUI apps which can run on Windows, Linux, and Mac for example almost out-of-the-box.

Other differences:

  • C# has LINQ, a built-in query syntax which captures expression trees and allows them to executed by alternative means (a bit like F#'s computation expressions / monads). Java has no analog.
  • C# has operator overloading, Java doesn't.
  • C# has Nullable, which allows you to treat ValueTypes like int which usually can't take on a null value as if they could (e.g. int? x = null). Java has special wrapper types like Integer for int used for boxing and unboxing primitives.
  • C# has local type inference (e.g. var x = 3 instead of int x = 3. Not nearly as aggressive as F#'s type inference, though), Java doesn't.
  • C# has "yield return" syntax which allows you to implement IEnumerables similar to F#'s sequence expressions. In Java you must implement it's Iterable using the full awkward interface.
share|improve this answer
add comment

In many respects, C# is a superset of Java, so you're actually well on the way.

Personally, I'd get a C# reference book (not a book that tries to teach the language, but a complete reference) and start looking for things that aren't familiar. Unfortunately, I'm not in a position to recommend a specific title. What I can say is that I learned VB.Net very quickly using a similar approach. In that case, I read VB.Net in a Nutshell, looking for differences from languages I knew previously.

In the longer term, I'd recommend reading Jon Skeet's book, as it really explains some of the more advanced topics very well.

share|improve this answer
    
I wouldn't say C# is a superset of Java. The way Java handles inner classes is a lot more different from how C# handles nested classes and there are also some variations with how native types are handled. –  davidk01 May 21 '11 at 21:36
4  
And there are some major differences around generics. –  Peter Taylor May 21 '11 at 22:47
    
+1 at Jon skeet's book, will be great for some language specifics. –  Ziv May 21 '11 at 23:46
    
@davidk01: You're quite right that there are major differences. (Including some important syntax, enums, checked exceptions, the entire framework etc). That is why I didn't say that Java is a subset of Java. I used the expression "in many respects", meaning "to a large extent". –  Kramii May 22 '11 at 9:16
add comment

I think you made the right call being honest, especially considering the short time frame. Many hiring managers who are trying to fill a C# position will consider someone whose only experience is with Java, especially if it's not a senior level position.

Even if you received an offer, it would probably be several weeks between accepting the job and actually starting. That would at least give you time to run through some programming books to get a better idea of the differences between the two languages.

Here is a good Wikipedia article about the differences between C# and Java:

http://en.wikipedia.org/wiki/Comparison_of_Java_and_C_Sharp

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.