C# allows user to implicitly define variables using var, but in java they have to be defined explicitly. CodePorting.com 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 { }
yep, its something like good and useful code convertor for me, and can help me to do more with my C# codes !! thanks for such a nice info.
You are most welcome and you can convert your code for free and its a cloud app so you dont have to download or install it just upload your code and it will be converted to java instantly and there are alot of other features that codeporting is offering and is trying to add more features in their App.