C # is a propaganda or useful technology?

zhaozj2021-02-17  77

C # (Reading "C Sharp") is Microsoft Company

A new programming language released last year, and is scheduled to appear in the Microsoft Occupational Developer Forum (PDC). C # is the latest achievements of Microsoft's researcher Anders Hejlsberg. C # looks like Java; it Including the process such as a single inheritance, interface, almost the same syntax, and compiled into an intermediate code and running. But C # has obvious differences from Java, which draws on the characteristics of Delphi, and COM (component object model) is Directly integrated, and it is the protagonist of Microsoft .NET Windows network framework.

In this article, I will examine the general motivation for creating a new computer language and will specify what causes C #, then I will introduce C # and it is similar to Java, C, C . Secondary I Some of the high levels, and basic differences that exist between Java and C # will be discussed. I will measure the knowledge required to measure when using large applications in a variety of languages ​​(or the lack of knowledge) End this article, and this is a major strategy for .NET and C #. Currently, C # and .NET can only use C # language rules, and a "D preview version" of Windows 2000, as well as a rapid increase in MSDN. The form is obtained in the form of (yet not finalized).

Microsoft C # language definitions are mainly inherited from C and C , and many elements in the language also reflect this. C # In designer, the options are more than Java, inherited, more than Java (for example, Structs), It also adds its own new features (for example, the source code version is defined). But it is too immature, it is impossible to squeezing java.c # also needs to evolve into a developer to accept and adopt the language. And Microsoft is currently it. This new language is also worth noting. At present, everyone's response is: "This is a counterattack for Java."

C # is more like Java, although Microsoft remains silent on this issue. This is also an expected thing, I think, because Java has recently succeeded in using Java companies report that they have improved in C in production efficiency.

The huge impact of Java and everyone's extensive acceptance of its extensive acceptance has been obviously illustrated by the number of programmers above this language and platform (estimated that there are two hundred and 500,000 programmers in the world use JAVA). The number of applications written in this language is surprising and has penetrated each level of calculations, including wireless computing and mobile phones (such as Japanese invented Java phones). C # can get such a courtesy in the user field? ? We must wait and wait, just like the CEO and Chairman Kalpathi S. Suresh of SSI, "I found that all of this is gradually. If C # does not exist, we can always return to Java or C and C . These are not entirely new technologies; they are only a market manufactured by big companies in greater sense. We must give them time to see how this is really impact on the IT industry. "

C # From Java inherited

Category: The declaration of Class Class is very similar to Java. This is reasonable because of experience tells us that the Java model works very well. Java's keyword import has been replaced into using, it has played the same role. A class start execution The starting point is a static method main (). The following Hello World program shows the basic form:

Using system; class hello {static void main () {console.writeline ("Hello, World");}}

In this example, the name of the SYSTEM points to a namespace including the basic C # Practical class collection. This namespace includes the Console class, which is used in this example to output a string. Class can be abstract And inherited: a class that is declared to Abstract cannot be instantiated; it can only be used as a base class. C # key Lock is like a java keyword Final, it declares that a class is not abstract, but it can't It is used as a base class for another class. Interface: Like in Java, an interface is an abstract definition of a set of methods. When a class or structure implements an interface, it must implement this interface defined in this interface. All methods. A single class can achieve several interfaces. Maybe some subtle differences will appear, but this feature does not change with Java. Boolean operation: Conditional expression results are Boolean data types, Boolean data types It is an independent data type in this language. From Boolean to other types of non-direct conversion processes. Boolean constants True and false are keywords in C #. Errors: such as Java, by throwing and capturing exceptions Objects to manage error handling procedures. Memory management: Automatic memory garbage collection by the underlying .NET framework. C and C inheritage

Compile: The program is directly compiled into a standard binary executable. If the previous Hello World program is saved as a text file and is named hello.cs, it will be compiled into the executable of the Hello.exe.

Structural: A C # structure is similar to C structures because it can include data declaration and method. However, it is not like C , C # structures and classes and does not support inheritance. However, with Java the same One of the structures can realize the interface.

Precamment: There is a pre-compiled instruction support condition compile, warning, error report, and compiling line control. Available precompiled instructions æ ‰:

#define

#undef

#if

#elif

#ELSE

#ENDIF

#Warning

#Error

#line []

There is no #include pseudo directive. You can't use the #define statement to assign the symbol, so there is no source code replacement concept - these symbols can only be used in the # i 和.. In the #Line directive The numbers (and optional names) can modify the line number and #WARNING and #Error output results.

Operator Overload: Some operators can be overloaded, while others can't. In particular, no assignment operator can be overloaded. The single-scale operator capable of being overloaded is:

-! ~ - True False

The binary operator that can be overloaded is:

- * /% & | ^ << >> ==! => <> = <=

C # unique features

C # The most fascinating place is the difference between it and Java, not similar place. This section (most of this series of second part) tells the C # implementation and Java different places or Java.

Middle code: Microsoft has left a lot of room when MSIL should be compiled into machine code. Microsoft claims that MSIL is not interpretative, but is compiled into machine code. It also understands many - If not most of the words - programmers think that the Java program must be slower than C. This implementation determines the MSIL-based program (referring to C #, Visual Basic, " MANAGED C "- a program that meets CLS-like version-and other languages ​​will exceed" interpretive "Java code. Of course, this is also required to get fact prove, because C # and other generated MSIL The compiler has not been released. But the general existence of Java Jit compile makes Java and C # are relatively identical. The "C # is compiled language and Java is interpretative," the statement is just commercial skills. Java intermediate code And MSIL is the language of the intermediate assembly form, which is compiled into machine code at runtime or during it.

Declinations in the namespace: When you create a program, you create one or more classes in a namespace. In this namespace (outside of the class), you may also declare interface, enumeration type And structural. You must use the using check "to reference the content of other namespaces.

Basic data types: C # has a broader data type than C, C or Java. These types are Bool, Byte, Ubyte, Short, USHORT, INT, UINT, LONG, ULONG, FLOAT, DOUBLE, and DECIMAL. Like Java All these types have a fixed size. Like C and C , each data type has two types of symbols and unsigned. The same is the same as Java, one character variable contains a 16-bit Unicode Character.c # new data type is the Decimal data type, for currency data, it can store 28-bit 10 credit numbers. Two basic classes: A class named Object is the base class of all other classes. And a String The class is also part of this language. As part of the language, there is a language that the compiler is likely to use - Whenever you write a string with quotation marks in the program, the compiler creates a String object. To save it.

Parameter delivery: Method can be declared to accept variable parameters. The default parameter transfer method is to deliver values ​​for basic data types .Ref keyword can be used to force a variable to pass through reference, which makes a variable accept a return value The .out keyword can also declare the reference delivery process, different from the REF is that it indicates that this parameter does not need the initial value.

Integration with COM: C # to Windows program's largest selling point may be seamless with COM, COM is Microsoft's Win32 component technology. In fact, it is eventually possible to write COM customers and server connections in any .NET language. C # written by the class can be subcatenamely a COM component; the generated class can also be used as a COM component, and then can be used, and the JScript language subscribers can get the third COM component. This. The result of the phenomenon causes an operational environment, and the components in this environment are network services, which can be used with any .NET language subclassification.

Index subscript: A index and attribute are similar to those who do not use the property name to reference class members but use the numbers in a square bracket (like the same as the array subscript).

Public class listbox: control {private string [] items; public string this [int index] {return {return {i} set {items [index] = value; repaint ();}}}

You can use a circulator to anonymously reference the internal array members, just like this:

Listbox listbox = ...; listbox [0] = "Hello"; console.writeline (listbox [0]);

Agents and Feedback: A proxy object includes information needed to access a specific method of a particular object. Just put it as a smart method pointer. The agent object can be moved to another place, then you can pass it. The existing method is called. A feedback method is a proxy for the agent. Event keyword is used in a method declaration that will be used as a proxy call when the event occurs.

in conclusion

The similarity between C # and C is a great advantage for companies that have trained investments in C and C . The programmers who are familiar with C will be easy to learn C #. And spend time learning Java Windows programmers (usually in the form of Visual J ) will learn C # faster than C programmers. In the programming industry, it is generally considered "If you learn Java, and know how C , then you have already understood 90% of C #. "

I hope this article gives you a probably impression of the connection between C # and Java and C . In general, I believe that C # provides a larger program performance and more suitable for programming performance, while having Java Beautiful and concise, which makes it more attractive than C .

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

New Post(0)