Codeporting has become a commonly used web based service by developers to convert their C# code to java which gives them the benefit of platform independence. C#2Java Engine accurately translates C# constructs to java.
Let me prove my point by taking the example of C# Indexers. For starters, Indexers creates classes or struct instances same way as of arrays but its not necessary that indexers are indexed by integer values, rather it depends on developers how he defines them.
Following examples shows how CodePorting C#2Java Engine translates C# Indexers to Java.
C# Code:
namespace CsPorter.Examples.Convert.Indexers
{
   public class Example14
   {
       void Method()
       {
           //int indexer
           int i = this[1];
           this[2] = i;
Â
           //enum, but int indexer in java
           i = this[Example14Enum.Two];
           this[Example14Enum.Two] = 1;
       }
Â
       //default java name: get/set
       internal int this[int index]
       {
           get { return index; }
           set { int i = value; }
       }
Â
       //java name should be changed to getByExample13Enum/setByExample13Enum
       internal int this[Example14Enum idx]
       {
           get { return (int)idx; }
           set { Example14Enum e = (Example14Enum)value; }
       }
   }
Â
   internal class Example141
   {
       void Method(Example14 Example)
       {
           //int indexer
           int i = Example[1];
           Example[2] = i;
Â
           //enum, but int indexer in java
           i = Example[Example14Enum.Two];
           Example[Example14Enum.Two] = 1;
       }
   }
Â
   internal enum Example14Enum
   {
       One, Two, Three
   }
}
Java Code:
package CsPorter.Tests.Convert.Indexers;
Â
// ********* THIS FILE IS AUTO PORTED FORM C# USING CODEPORTING.COM *********
Â
import com.codeporting.csharp2java.java.Enum;
Â
public class Test14
{
   private void method()
   {
       //int indexer
       int i = this.get(1);
       this.set(2, i);
Â
       //enum, but int indexer in java
       i = this.getByExample14Enum(Example14Enum.TWO);
       this.setByExample14Enum(Example14Enum.TWO, 1);
   }
Â
   //default java name: get/set
   int get(int index) { return index; }
   void set(int index, int value) { int i = value; }
Â
   //java name should be changed to getByExample13Enum/setByExample13Enum
   int getByExample14Enum(/*Example14Enum*/int idx) { return (int)idx; }
   void setByExample14Enum(/*Example14Enum*/int idx, int value) { /*Example14Enum*/int e = (/*Example14Enum*/int)value; }
}
Â
class Example141
{
   private void method(Example14 Example)
   {
       //int indexer
       int i = Example.get(1);
       Example.set(2, i);
Â
       //enum, but int indexer in java
       i = Example.getByExample14Enum(Example14Enum.TWO);
       Example.setByExample14Enum(Example14Enum.TWO, 1);
   }
}
Â
/*enum*/ final class Example14Enum extends Enum
{
        private Example14Enum(){}
   public static final int ONE = 0; public static final int TWO = 1; public static final int THREE = 2;
Â
        static {
                Enum.register(new Enum.SimpleEnum(Example14Enum.class, Integer.class) {{
                addConstant(“ONE”, ONE);
                addConstant(“TWO”, TWO);
                addConstant(“THREE”, THREE);
                }});
        }
Â
}
Â
It is clear from the above example that CodePorting C#2java accurately converts C# indexers to compile-able java code.
Newly added articles and documentation pages
- Automatically convert C# Indexers to Java using CodePorting Engine
- List of Conversions Supported by CodePorting C#2Java Engine
- CodePorting C#2Java Engine handles code formatting while converting C# code to java
- Automatically Convert C# Unsigned Integer Types to java using CodePorting Engine
About CodePorting C#2Java App
CodePorting helps you make your .NET applications cross platform compatible and allows migrating your .NET solutions, projects and files into Java in the cloud. Other than speed and accuracy of conversion; port your C# code directly either by uploading .cs files contained in a .zip file or import directly from popular version control repositories like GIT, Mercurial HG and SubVersion. You can also download a Microsoft Visual Studio plugin and convert C# code in the real time without leaving the development environment. You may also build your own customized code conversion applications using CodePorting APIs.
Read more about CodePorting
- Start converting C# Apps and source code to Java
- CodePorting Homepage
- CodePorting C#2Java Homepage
- CodePorting Documentation
- Watch out CodePorting introductory video
Contact Us
Suite 163, 79 Longueville Road
Lane Cove, NSW 2066, Australia
CodePorting ““ Your CodePorting Experts
Skype Name: CodePorting
Email: support [@] codeporting [dot] com
Â
Â
Â