1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Automatically convert C# Implicit Type var to java using CodePorting Engine

Discussion in 'Java' started by zarfishan, Jun 6, 2012.

  1. zarfishan

    zarfishan New Member

    Joined:
    Jun 4, 2012
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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 replace 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:
    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:
    Code:
    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
    {
    }
     
    Last edited by a moderator: Jun 6, 2012

Share This Page