"Continuous Update" Considerations for converting. NET code to Java code

Source: Internet
Author: User

Most universities in the country most of the software-related majors force students to learn C and Java, but. Net of several languages can be said to be selected.

Because Visual Studio is relatively easy to use on the Windows platform, some alumni learn about the. NET development technology before they are in the university's Java class.

This class requires some code conversion techniques to help you learn java.

Before that, I spit my groove. TinyMCE Editor, it does not correctly dye some vb.net keywords, such as async, NameOf, Aggregate. Some keywords in C # are also not dyed correctly, such as __arglist.

Since I started Java class this semester, the mistakes in the code are welcome to correct me.

1. Enumeration type

Vb

 Public Enum Direction    Right = 1 Downright down Downleft left upleft up     UpRight End Enum             

C#

         Public enum   Direction        {Down            = 1,            downleft, left            ,            Upleft, up            ,            UpRight, right            ,            downright        } 

Converting to Java is like this. It feels similar to C + +/CLI and c++/cx enum class.

If the previous enumeration is long, it is best to write a small program to convert it.

 Public enumDirection {Down (1), Downleft (2), left (3), Upleft (4), Up (5), UpRight (6), right (7), downright (8)    Private int__value;    PrivateDirection (intvalue) {         This. __value =value; } @Override PublicString toString () {returnString.valueof ( This. NCode); }}

That __value is I copy. NET reference source, if dislike can rename.

2. Exceptions

Java exceptions if it's not runtimeexception, you have to declare it with throws, Otherwise, like accessviolationexception, this type of error can only be handled in UnhandledException (Errorlistener).

Conversion code when writing a bunch of throws more trouble, write a layer on the next layer of forgetting what is the exception.

This is better to do, as long as it is not a fatal exception, the custom exception will inherit RuntimeException good. Several of the bands need to be intercepted with Errorlistener with throws anomalies.

class extends runtimeexception{    public  pointoutofscreenexception () {        Super("point out the screen ...");    }}

3. Inference for identifier types

Vb

Dim  NewStringBuilder

C#

var New StringBuilder ();

Convert to Java by copying and pasting Dafa, copying the class name and pasting it into the beginning

New StringBuilder ();

4. C # unsafe mode, VB and F # various tune run libraries unique operators, dynamic, Async, await, LINQ, unsigned type ....

Vb

Async FunctionLoadimages (device as Canvasdevice) as Task foresttiles=Await Spritesheet. LoadAsync (Device,$"spritesheets/foresttiles{NameOf(ImageID)}. png",NewVector2 ( -, -), Vector2.zero) Wizardwalk=Await Spritesheet. LoadAsync (Device,"Spritesheets/wizardwalkright.png",NewVector2 ( -,192),NewVector2 ( -, Max)) Wizardidle=Await Spritesheet. LoadAsync (Device,"Spritesheets/wizardidleright.png",NewVector2 ( -,192),NewVector2 ( -, Max))        End Function

C#

        Async Task loadimages (canvasdevice device) {foresttiles=await Spritesheet. LoadAsync (Device,$"spritesheets/foresttiles{nameof(ImageID)}. PNG",NewVector2 ( -, -), Vector2.zero); Wizardwalk=await Spritesheet. LoadAsync (Device,"Spritesheets/wizardwalkright.png",NewVector2 ( -,192),NewVector2 ( -, Max)); Wizardidle=await Spritesheet. LoadAsync (Device,"Spritesheets/wizardidleright.png",NewVector2 ( -,192),NewVector2 ( -, Max)); }

Vb

     Public FunctionCalculateclipgeometry (Resource as Icanvasresourcecreator, Sourcepoint as Vector2, geometies as Canvasgeometry(), ScreenSize as Size) asCanvasgeometryDimGEOS =AggregateGeoinchgeometies  let Lines=AggregateTesinchGeo. Tessellate  from lninch{New LineSegment(TES. Vertex1, TEs. VERTEX2),New LineSegment(TES. Vertex1, TEs. VERTEX3),New linesegment(tes. Vertex3, TEs. VERTEX2)}SelectLn Distinct  into ToArraySelectRays =AggregateTesinchGeo. Tessellate   from lightinch{New LineSegment(Sourcepoint, TEs.) VERTEX1),New LineSegment(Sourcepoint, TEs.) VERTEX2),New linesegment(Sourcepoint, TEs. VERTEX3)} Where  not(AggregateLinchLines Where light. Raytoboundary (screensize). Hasintersection (l)   into any)SelectLight into ToArray Where rays.length  >=2 AndAlsoRays (0). Name like "ln*"Let   Fir=Rays.firstSelectARR =AggregatelninchRays Order by Ln. Angle (Fir)  into ToArraySelect canvasgeometry. Createpolygon (Resource, {Arr.First.Point2, Arr.First.RayToBoundary (screensize). Point2, Arr.Last.RayToBoundary (screensize). Point2, Arr.Last.Point2})  into ToArrayReturngeos. UnionEnd Function

C#

 Public unsafe void Addthree (__arglist) {    varnew   argiterator(__arglist );     var a = (byte*)TypedReference. Toobject (args. Getnextarg ());     *a+=3;}

Java

// TODO: Write it yourself again. Converting this code directly is a waste of time!

I have to go to class, this time I will write here. Like Java can find out the description of unreasonable places, but do not spray.

"Continuous Update" Considerations for converting. NET code to Java code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.