Congratulations to all the winners of April 2013, they have won INR 3400 cash and INR 20147 worth prizes !
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 18179 |  Welcome, Guest!   Register  Login
 Home > Forums > C# > How to Convert C# Using statement to Java ...
Zarfishan

How to Convert C# Using statement to Java

Replies: 0 | Posted by: Zarfishan on 5/27/2012 | Category: C# Forums | Views: 325 | Status: [Member] | Points: 10  


CodePorting C#2Java engine intelligently translates the C# using statement and handle this situation by producing try/catch block in java code. This Technique converts C# code to java code with same formatting ready to be complied.

Following example shows migration of C# using statement in java:

C# Code:

using System.IO;

namespace CsPorter.Tests.Convert.LanguageConstructs.UsingStatement
{
public class Test2
{
void Method()
{

//some comments (vertical indent)
using (Stream stream = new FileStream("nowhere", FileMode.Open))
{
stream.ReadByte();
}

//horisontal indent
using (Stream stream = new FileStream("nowhere", FileMode.Open))
{
stream.ReadByte();
}
}
}
}



Java code generated by CodePorting:
package CsPorter.Tests.Convert.LanguageConstructs.UsingStatement;

// ********* THIS FILE IS AUTO PORTED FORM C# USING CODEPORTING.COM *********

import com.codeporting.csharp2java.System.IO.Stream;
import com.codeporting.csharp2java.System.IO.FileStream;
import com.codeporting.csharp2java.System.IO.FileMode;

public class Test2
{
private void method() throws Exception
{

//some comments (vertical indent)
Stream stream = new FileStream("nowhere", FileMode.OPEN);
try /*JAVA: was using*/
{
stream.readByte();
}
finally { if (stream != null) stream.close(); }

//horisontal indent
Stream stream1 = new FileStream("nowhere", FileMode.OPEN);
try /*JAVA: was using*/
{
stream1.readByte();
}
finally { if (stream1 != null) stream1.close(); }
}
}


It is clear from above example that CodePorting C#2Java engine automatically generated the try/catch code to handle the using statement.


Reply | Reply with attachment | Alert Moderator

 Responses below this adGet hundreds of .NET Tips and Tricks videos

  No reply found.


Reply - Please login to reply


Click here to login & reply

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/20/2013 4:58:05 AM