我应该如何转换成Java代码到C#代码? [英] How should I convert Java code to C# code?

查看:103
本文介绍了我应该如何转换成Java代码到C#代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我移植一个Java库为C#。我使用Visual Studio 2008中,所以我没有停产微软Java语言转换助手程序(JLCA)。

I'm porting a Java library to C#. I'm using Visual Studio 2008, so I don't have the discontinued Microsoft Java Language Conversion Assistant program (JLCA).

我的方法是创建一个新的解决方案一个类似的项目结构到Java库,并在此后的Java代码复制到C#文件,并将其转换为有效的C#行由行。考虑到我发现的Java容易阅读,在两种语言的细微差别都让我感到惊讶。

My approach is to create a new solution with a similar project structure to the Java library, and to then copy the java code into a c# file and convert it to valid c# line-by-line. Considering that I find Java easy to read, the subtle differences in the two languages have surprised me.

有些事情很容易端口(命名空间,继承等),但一些事情已经出乎意料的不同,如在嵌套类的私有成员,压倒一切的虚方法的知名度和内置类型的行为。我不完全理解这些东西,我敢肯定有很多我还没有看到其他差异。

Some things are easy to port (namespaces, inheritance etc.) but some things have been unexpectedly different, such as visibility of private members in nested classes, overriding virtual methods and the behaviour of built-in types. I don't fully understand these things and I'm sure there are lots of other differences I haven't seen yet.

我还有很长的路要走在这个项目上。什么样的规则经验法则,我可以这个转换过程中应用到正确管理语言上的差异?

I've got a long way to go on this project. What rules-of-thumb I can apply during this conversion to manage the language differences correctly?

推荐答案

您这样做的唯一理智的方式,你可以...最大的帮助将这个文件从敢于奥巴桑乔列出两种语言之间的差异:

Your doing it in the only sane way you can...the biggest help will be this document from Dare Obasanjo that lists the differences between the two languages:

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

BTW,更改所有的getter和setter方法​​的属性...不需要有C#库函数只是一样的Java库,除非你要完美的接口兼容性。

BTW, change all getter and setter methods into properties...No need to have the C# library function just the same as the java library unless you are going for perfect interface compatibility.

这篇关于我应该如何转换成Java代码到C#代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆