C# 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
{}