我只想澄清一件事。这不是哪个更好的问题,这部分我留给别人讨论。我不在乎。 我在面试时被问到过这个问题,我想多了解一点可能会有用。

以下是我能想到的:

Java is "platform independent". Well nowadays you could say there is the Mono project so C# could be considered too but I believe it is a bit exaggerating. Why? Well, when a new release of Java is done it is simultaneously available on all platforms it supports, on the other hand how many features of C# 3.0 are still missing in the Mono implementation? Or is it really CLR vs. JRE that we should compare here? Java doesn't support events and delegates. As far as I know. In Java all methods are virtual Development tools: I believe there isn't such a tool yet as Visual Studio. Especially if you've worked with team editions you'll know what I mean.

请补充其他你认为相关的。

更新: 我突然想到,Java在类、方法等上没有自定义属性。真的是这样吗?


当前回答

c#具有自动属性,这非常方便,它们也有助于保持你的代码更简洁,至少当你的getter和setter中没有自定义逻辑时是这样。

其他回答

另一个很好的资源是http://www.javacamp.org/javavscsharp/ 本网站列举了许多例子,说明了这两种编程语言之间的几乎所有差异。

关于属性,Java有注释,它的工作方式几乎相同。

泛型:

使用Java泛型,您实际上无法获得. net所获得的任何执行效率,因为当您在Java中编译泛型类时,编译器会删除类型参数并在所有地方替换Object。例如,如果你有一个Foo<T>类,java编译器生成字节码,就好像它是Foo<Object>。这意味着转换和装箱/开箱都必须在“后台”中完成。

我已经使用Java/ c#有一段时间了,在我看来,语言层面的主要区别是,如你所指出的,委托。

以下是Dare Obasanjo关于c#和Java之间差异的深度参考。在两者之间切换时,我总是会参考这篇文章。

http://www.25hoursaday.com/CsharpVsJava.html

请通过下面给出的链接 msdn.microsoft.com/en-us/library/ms836794.aspx 它涵盖了c#和java之间的相似点和不同点

c#具有自动属性,这非常方便,它们也有助于保持你的代码更简洁,至少当你的getter和setter中没有自定义逻辑时是这样。