The first lesson of C # Learning

Source: Internet
Author: User

There are many similarities between C # and Java, but there are some differences. Just went to the library this afternoon to borrow a C # introductory book, in a simple introduction, I learned a few differences:

1. There are only 8 basic data types in Java, data types do not have unsigned and signed distinctions, and basic data types in C # are redundant in Java because numeric values in C # have signed and unsigned types.

2. There are structural types in C #, which should be borrowed from the concept of structs in C/s + +. There is no such data type in Java.

3. In terms of the use of arrays, C # 's multidimensional arrays are declared in particular, by adding commas in brackets after the array name and specifying the length of each dimension when initializing. When you declare a multidimensional array, such as Java or C + +, the array name is followed by a number of brackets.

4. In the control structure, C # adds the foreach statement result to C + +, somewhat similar to the for loop iteration in Java, but I feel that the for iteration function in Java is more powerful. Goto end Sentence in C # I saw it for the first time, and I thought it was special.

Parameter type of the method

Value passing and reference passing: When a method is called, the program first passes the value of the argument to the corresponding parameter, the argument and the shape delegate to the same object for the arguments of the reference type, and for the parameter of the value type, the value of the argument is assigned a copy to the formal parameter. C # Provides reference passing methods for method parameters, which are decorated with the "ref" keyword by referring to passed method parameters:

public static void function (ref int x,ref int y) {}

The REF keyword is also required to be added before the argument is called

Output type parameter:

The output type parameter is decorated with the Out keyword. The output parameter is also referenced by reference, but the formal parameter must be assigned in the method.

Public decimal gain (decimal x, int n, out decimal interest) {}

Array-type parameters:

The parameter type of the method can be an array, and with the params in front of the parameter, the parameter becomes an array-type parameter, analogous to the mutable parameter in Java.

The first lesson of C # Learning

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.