Turning to C #, starting from the subtle place - write to VB, VC programmer

zhaozj2021-02-16  54

Maybe I am like me, many programmers are preparing or have begun to turn to C #, and below, based on some VB, VC programmers should notice a little detail when writing C # codes.

Grammatical habits

1.1 Predefined and import

VC programmer: For #include, it must be familiar with it, it is changed to using in C #, but it is also necessary, such as:

Using system;

...

Console.writeline ("Helo World!");

with

System.Console.writeline ("Helo World!");

The effect is the same. And it is important to pay attention to the "::", "->" and other wrong characters have been abandoned in C #. Only "."

VB Programmer: In fact, this step is referenced in "References", such as a function in Visual Basic for Application, or VBA.NOW.

In short, from now on, it is necessary to adapt to using.

1.2 case and notes

This Point VC programmer should be very good, and VB programmers must develop good habits from the beginning. It is worth noting that: "//" can't follow the connection "/" b. "/ * * /" Cannot be used nested.

1.3 About Main () function

I have to pay attention to friends who often use a Cezed console program that the main () function in the C # must be included in a class.

1.4 String class

VC programmer: The following usage is not strange

String s = "abcd" "efgh"

Char a = s [5] // This time a value is 'e'

VB programmer: In fact, this usage is equivalent to:

DIM S As String

s = "abcd" "efgh"

A = MID ("S", 5, 1) 'This time A is' e'

2. Data type

2.1 Boolean

VC programmers: C # uses the True False in VB, not the result of the previous 0 indicates the false, and not 0 is true.

2.2 Character Type

VC programmer: In C , this variable represents the ASCII code corresponding to the value, and can be used as part of the integer to participate in the value, this is not allowed in C #.

VB programmer: Similar to VB: chr (13) is represented by the carriage return.

2.3 decimal type

This is a new type that is also very wide in the actual application.

3 compilation

The C compilation process is saved -> Compile -> ", and is only the compiled program can run. The VB program is more like running while compiling, and the compilation process of the C # is just a combination of the advantages, it is directly compiled into an EXE or DLL, and skip the process of the target file (OBJ), so C # compile There is no need to include the linker in the unit.

In addition, we can also perform full compilation through CSC / Nooutput Temp.cs, do not generate an exe file, can check the syntax error of the code, similar to the Start With Full Compile in VB.

A new language, understand her thoughts, adapt to her grammar, may take a certain amount of time, let us start from the point, start a new DOTNET world!

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

New Post(0)