C # and Java's difference - reading

xiaoxiao2021-03-06  26

C # and Java distinguish: 1. Properties: Definition and access in Java use GET and SET methods, it can be appeared. C # is a real attribute, and the GET and SET must appear at the same time when defined, and you can use it when you are. Do not use GET, SET

2. Object index is the object array public story this [int index] {

3.C #, the default is Protect without any range of modifiers, so you can't access it outside the class.

4. Because Java stipulates that there can be only a public class in a file, and the name of this class must be exactly the same as the file name, this is a difference.

5. In C #, it is positioned in the MAIN method. If there is no MAIN in a program, it will "find an error in the entrance". Don't write MAIN to Main 哟

6.C # predefined simple data types are more than Java. For example, C # has Unit, ie unsigned integers

7. Forget the Static Final modifier in Java. In C #, constant can use a Const keyword declaration C # designer also adds the readonly keyword, the Readonly domain can only be set by the constructor of the initializer or class 8. The entry point of the utility class: C # is the weight of Main Load (in java), allows for INT return value and empty parameters

9. In Java, the Switch statement can only handle an integer. However, the Switch statement in the C # is different, and it can also handle the character variable. Consider the C # code of the string variable with Switch statement below

10.C # Nothing >>> Shift operator

11.GOTO Keywords: Java No goto Keywords. In C #, GOTO allows you to go to the specified label. However, C # treats GOTO at a very cautious attitude, such as it does not allow GOTO to transfer to the inside of the statement block. In Java, you can add BREAK or Continue to replace C # in GOTO with a label statement.

12.int [] x = {0, 1, 2, 3}; int x [] = {0, 1, 2, 3}; but in C #, only the first line of code is legal, [] cannot be placed in variables The name is after the name.

13. Unlike Java, C # allows you to specify an alias for classes in the namespace or namespace: use theconsole = system.console;

14. In Java, the name of the package is also an actual existing entity, which determines the directory structure of the .java file. In C #, the physical package and logic name is completely separated .NET in the entity of the assembly (Assembly). Each program set contains a Manifest structure. The Manifest lists the files contained in the assembly, control which types and resources are exposed to the assembly, and map the reference to these types and resources to files that contain these types and resources. The assembly is self-contained, and an assembly can be placed within a single file or split into multiple files. This package mechanism of .NET solves the problem facing the DLL file, that is, the inexperity DLL Hell problem.

15. In Java, java.lang package is the default package, there is no default package in C #

16. Access modifiers in C # The basic correspondence in Java, but there is more intence. In short, C # has five types of accessibility, as shown below:

PUBLIC: Members can access from any code. Protected: Members can only access from derived classes. INTERNAL: Members can only access internal access from the same assembly. Protected INTERNAL: Members can only access derived classes within the same program. Private: Members can only access within the current class.

17. Due to the Final keyword in C #, if you want a certain class no longer derived, you can use SeaVa 18. Unlike Java, the interface in the C # cannot contain a domain (Field). Also note that in C #, all methods in the interface are common methods by default. In Java, the method declaration can carry a public modifier (even if it is not necessary), but in C #, the method explicitly specifies the PUBLIC modifier to be illegal. For example, the following C # interface will generate a compilation error.

19. The IS operator in C # is the same as the InstanceOf operator in Java, and both can be used to test whether an instance of an object belongs to a specific type. There is no operator in Java's AS operator equivalent to C #. The AS operator is very similar to the IS operator, but it is more "in-heart": If the type is correct, the AS operator will try to convert the object reference to the target type; otherwise, it sets the variable reference to null.

20.C # still retains the C memory manual management method, which is suitable for use in extremely important occasions, while this is not allowed in Java

21. In C #, all exceptions are derived from a class called Exception.

22. Enumerator, is an ENUM type (Java none), uses it as a type of variable value, thereby limiting the variable possible range to the value that appears in the enumerator.

23. Structure (STRUCT) is similar, and the structure is a value type, which stores in the stack or embedded, the structure can implement the interface, you can have a member as a class, but the structure does not support inheritance

24. The first part of the attribute declaration syntax is similar to the domain statement, and the second part includes a set process and / or a GET process.

25. Passivity: In the simple data type of data type in Java, the value of the value; if adding REF is passed in the c #, the parameter is changed inside, and the external variable is followed together. Variable); plus OUT is basically the same as REF, but OUT does not require parameters to be initialized.

26.c # preserved the pointer. Unsafe

27. Agent: Delegate can be seen as a function pointer agent in C or other languages ​​to encapsulate the calling method. You can write a method in the class and create a proxy on that method, and this agent can be passed to the second method. In this way, the second method can call the first method. The agent is a reference type derived from the public base class system.delegate. Definitions and Use Agents include three steps: declaration, create an instance, call. The agent declaration with Delegate declaration grammar.

转载请注明原文地址:https://www.9cbs.com/read-65179.html

New Post(0)