DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone >

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

Zarfishan Zahid user avatar by
Zarfishan Zahid
·
Jun. 01, 12 · · News
Like (0)
Save
Tweet
862 Views

Join the DZone community and get the full member experience.

Join For Free

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

 

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

 

Java (programming language) Convert (command) Engine

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Handling Sensitive Data: A Primer
  • How to Integrate Zoom in React Application?
  • ERP Integration Guide | Common Scenarios, Challenges, and Methods
  • Best Practices for Resource Management in PrestoDB

Comments

Partner Resources

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo