Syntax differences between Java and C # (constantly updated ... )

Source: Internet
Author: User

1.static Keywords:

  Static members in Java can be called by object and class name;

In C #, a static member can only be called by a class and cannot be called by an object.

2.for Loop:

  In Java, you can add a tag to the for front and then break to specify a for loop for the token in the For loop;

In C #, break is jumping out of the current for loop without marking this thing.

3. Constructor Call:

  In Java, calling a constructor in a constructor is through "This (parameter 1, parameter 2 ...)" Called directly in the function body of the constructor;

In C #, it is passed after the constructor ": this (parameter 1 ...)", for example----public person (string Name,int age,int weigh): this (name,age).

4. Constructing code blocks and static code blocks

  In Java, you can define building blocks of code, which means that in a class, you write code directly in the "{Write Code}", which is loaded every time a class object is instantiated, and the static code block means "static{write code}", which is executed once when the class is loaded. Executes only once. It is the use of the class of things to execute the above two concepts, if only the declaration (not initialized or simply initialized to null) is not loaded, such as in the person class has the above two concepts, then declare the person p=null, so that the above two concepts will not execute the code, If person is p=new person (), then the two concepts are called. A static block of code executes before a block of code is constructed, because there are classes before objects. Execution order: Static code block--static property creation and initialization--with default merit property initialization--Construction code block--constructor

In C #, there is no concept of building blocks of code and static code blocks.

Syntax differences between Java and C # (constantly updated ... )

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.