Using CodePorting C#2Java App developers can now migrate C# language constructs even if they don't have a counterpart in java.  We have already shown you such example in our previous blogs like converting C# unsigned integer types to java using CodePorting C#2java App.  A struct in C# is a user-define type which is declared same as a class, the only difference is that it cannot be inherited from any class and no class can be inherited from it. In this blog we will show you that using CodePorting C#2Java App developers can easily convert C# construct to java in cloud.

See following Example:

C# Code:

 

Code
using System;
Code
using System.Collections.Generic;
Code
using System.Linq;
Code
using System.Text;
Code
Code
namespace CSharp2Java.Samples.Convert.Structs
Code
{
Code
    public class StructsExample
Code
    {
Code
        public struct SimpleStruct
Code
        {
Code
            public static SimpleStruct DEFAULT = new SimpleStruct();
Code
        }
Code
Code
        SimpleStruct ss;
Code
Code
        private void Method()
Code
        {
Code
            SimpleStruct simpleStruct = new SimpleStruct();
Code
            Method(simpleStruct);
Code
            Method(ss);
Code
            Method(this.ss);
Code
            Method(SimpleStruct.DEFAULT);
Code
            Method(new SimpleStruct());
Code
            Method(Get());
Code
        }
Code
Code
        private void Method(SimpleStruct s)
Code
        {
Code
        }
Code
Code
        private SimpleStruct Get()
Code
        {
Code
            return ss;
Code
        }
Code
Code
    }
Code
}

 

Java Code:

Code
package CSharp2Java.Samples.Convert.Structs;
Code
Code
// ********* THIS FILE IS AUTO PORTED FORM C# USING CODEPORTING.COM *********
Code
Code
import com.codeporting.csharp2java.System.msObject;
Code
import com.codeporting.csharp2java.java.Struct;
Code
Code
public class StructsExample
Code
{
Code
    public static /*struct*/ class SimpleStruct extends  Struct
Code
    {
Code
         public SimpleStruct(){}
Code
Code
        public static SimpleStruct DEFAULT = new SimpleStruct();
Code
    }
Code
Code
    private SimpleStruct ss = new SimpleStruct();
Code
Code
    private void method()
Code
    {
Code
        SimpleStruct simpleStruct = new SimpleStruct();
Code
        method(simpleStruct.Clone());
Code
        method(ss.Clone());
Code
        method(this.ss.Clone());
Code
        method(SimpleStruct.DEFAULT.Clone());
Code
        method(new SimpleStruct());
Code
        method(get().Clone());
Code
    }
Code
Code
    private void method(SimpleStruct s)
Code
    {
Code
    }
Code
Code
    private SimpleStruct get()
Code
    {
Code
        return ss;
Code
    }
Code
}

 

It is clear from the above example that in java a class has been generated by CodePorting C#2Java App for struct defined in C#.

 

Newly added articles and documentation pages

Overview:   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

Contact Us

Suite 163, 79 Longueville Road

Lane Cove, NSW 2066, Australia

CodePorting – Your Code Porting Experts

Phone: +61 2 8901 3609

Email: support [@] codeporting [dot] com