Automatically convert C# Implicit Type var to java using CodePorting Engine
Join the DZone community and get the full member experience.
Join For FreeC# allows user to implicitly define variables using var, but in java they have to be defined explicitly. CodePorting C#2Java Engine allows user to automatically translate C# code to java code by replacing the type var with correct datatype which result in compile able java code.
Following example shows migration of C# var statement in java:
C# Code:
using System;
using System.Collections.Generic;
using System.IO;
namespace CodePorting.Convert.LanguageConstructs.varStatment
{
public class Test1
{
static void Main()
{
int d = 2;
var x = 5 + d;
var y = 5.5;
var z = "this is test";
var myEmployee = new Employee();
var list = new List();
for (var xx = 1; x < 10; x++)
Console.WriteLine(xx);
using (var file = new StreamReader("C:\\myfile.txt"))
{
}
string[] words = { "aPPLE", "BlUeBeRrY", "cHeRry" };
foreach (var ul in words)
{
Console.Write( ul.ToUpper());
}
}
}
class Employee
{
}
}
Java Code generated by CodePorting:
package CodePorting.Convert.LanguageConstructs.varStatment;
// ********* THIS FILE IS AUTO PORTED FORM C# USING CODEPORTING.COM *********
import java.util.ArrayList;
import com.codeporting.csharp2java.System.IO.StreamReader;
public class Test1
{
static void main() throws Exception
{
int d = 2;
int x = 5 + d;
double y = 5.5;
String z = "this is test";
Employee myEmployee = new Employee();
ArrayList list = new ArrayList();
for (int xx = 1; x < 10; x++)
System.out.write(xx);
StreamReader file = new StreamReader("C:\\myfile.txt");
try /*JAVA: was using*/
{
}
finally { if (file != null) file.close(); }
String[] words = { "aPPLE", "BlUeBeRrY", "cHeRry" };
for (String ul : words)
{
System.out.printf( ul.toUpperCase());
}
}
}
class Employee
{
}
Newly added articles and documentation pages
- Automatically convert C# Implicit Type var to java using CodePorting Engine
- Automatically convert C# using statement to java using CodePorting Engine
- Download CodePorting C#2Java API Samples for Ruby & C# on GitHub & CodePlex
- Convert C# Proprties to Java Online using CodePortingC#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
CodePorting – Your CodePorting Experts
Skype Name: CodePorting
Email: support [@] codeporting [dot] com
Opinions expressed by DZone contributors are their own.
Comments