Skip to main content

Convert C# Struct To Java Using CodePorting Engine

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
No replies
Anonymous

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:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharp2Java.Samples.Convert.Structs
{
public class StructsExample
{
public struct SimpleStruct
{
public static SimpleStruct DEFAULT = new SimpleStruct();
}

SimpleStruct ss;

private void Method()
{
SimpleStruct simpleStruct = new SimpleStruct();
Method(simpleStruct);
Method(ss);
Method(this.ss);
Method(SimpleStruct.DEFAULT);
Method(new SimpleStruct());
Method(Get());
}

private void Method(SimpleStruct s)
{
}

private SimpleStruct Get()
{
return ss;
}

}
}

Java Code:

package CSharp2Java.Samples.Convert.Structs;

// ********* THIS FILE IS AUTO PORTED FORM C# USING CODEPORTING.COM *********

import com.codeporting.csharp2java.System.msObject;
import com.codeporting.csharp2java.java.Struct;

public class StructsExample
{
public static /*struct*/ class SimpleStruct extends Struct
{
public SimpleStruct(){}

public static SimpleStruct DEFAULT = new SimpleStruct();
}

private SimpleStruct ss = new SimpleStruct();

private void method()
{
SimpleStruct simpleStruct = new SimpleStruct();
method(simpleStruct.Clone());
method(ss.Clone());
method(this.ss.Clone());
method(SimpleStruct.DEFAULT.Clone());
method(new SimpleStruct());
method(get().Clone());
}

private void method(SimpleStruct s)
{
}

private SimpleStruct get()
{
return ss;
}
}

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

- Convert C# Struct To Java Using CodePorting Engine
- Convert C# Proprties to Java Online using CodePortingC#2Java App
- Automatically Convert C# Unsigned Integer Types to java using CodePorting Engine
- Supported Conversions by CodePorting C#2Java App

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

- 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
Web: Codeporting.com
Phone: +61 2 8901 3609
Email: support [@> codeporting [dot> com