C # Quick (one)

zhaozj2021-02-11  146

In some terms, I try to do consistency with the terms described with MSDN's Chinese information.

Title: C # Quick (Quick C #)

-------------------------------------------------- ------------------------------ Play by Aisha Ikram. Usage Environment: .NET, C #, WIN XP, WIN 2000

introduction

C # is a language, with a characteristic of C , like Java's programming style, and like Basic's rapid development model. If you already know C , this article will allow you to quickly master C #'s grammar in less than an hour. Familiar with Java is better, because Java's program structure, packages and garbage collection concept help you know C # faster. So when discussing the C # structure, I will assume that you understand C .

This article discusses the construction and characteristics of C # language, and uses a concise and you can understand some code examples. We will try to let you see these codes to understand these concepts.

Note: This article is not written for the C # master (C # Gurus). This is a Chinese article on C # learning or initiator.

Below is a directory of the C # issue that will be discussed:

Program Structure Name Space Data Type Variable Operator and Expression Enumeration Statements (STRUCTS) Modifiers Properties Data (Arrays) ARRAYS Indexers (Indexers) boxes and unpacking operations (delegates) inheritance and polymorphism

The following content will not be discussed:

C and C # Who are more common with type conversion exception processing .NET library, such as garbage recycling, thread, and file processing .NET library

------------------- Program structure ------------------- This is like C , C # is a pair Sensitive language sensitive language, semicolon ";" is a separator between statements. Unlike C , C # is declared in the code file (header) and implementation code file (CPP file) not independently exists, all code (class declarations and class implementations) are located in a file extension CS.

Let us look at the Hello World program in C #.

Using system;

Namespace mynamespace

{

Class HelloWorld

{Static void main (string [] args) {console.writeline ("Hello World");}}}

Everything in C # is packaged into a class, and the class C # is encapsulated into a namespace (just like a file in a folder). Similar to C , the main method is the entry point of your program. The C main function call name is "main", and the C # main function is "main" at the bottom of the uppercase letter M.

There is no need to put the semicolon separator in the class sentence block or the structure definition. This is required in C , but it is not in C #.

------------------- Name Space ------------------- Every class is packaged into a namespace . The concept of namespace is exactly the same as C , but the frequency of the namespace is used in C among C . You can access a class using a dot qulifier. In the top of the Hello World program, MyNameSpace is a namespace. Now think about this problem now, you want to access the HelloWorld this class how to operate from the namespace of some other classes. This has an example:

Using System; Namespace Anothernamespace {Class Anotherclass {Public Void Func () {Console.Writeline ("Hello World");}}}

Now, from your HelloWorld class, you can access the namespace of this AnotherNameSpace this:

using System; using AnotherNameSpace; // you will add this using statementnamespace MyNameSpace {class HelloWorld {static void Main (string [] args) {AnotherClass obj = new AnotherClass (); obj.Func ();}}}

In the .NET library, System is located in the top layer named space, and other namespaces have this namespace. By default, there is a global namespace, so a class defined outside the namespace will directly under this global namespace; therefore, you can access this class without any point limiter.

You can also define nested namespaces below.

The "#include" in USINGC indicates that the "using" keyword by the C # is replaced, and it follows the name of a named space. As the "Using System" above. "System" is another unpacking namespace and the most underlying namespace in the class. The base class of all objects is derived from the Object class in the System namespace.

------------------- Variables ------------------ Receptes below, C # is almost With C :

Unlike C , the C # variable must be initialized before being accessed; otherwise it will be reported when compiling. Therefore, it is impossible to access a uninterected variable. You will not access an uncertain pointer in C #. (Translator Note: Strictly speaking C # has been synchronized by the pointer, limiting more stringent. Some information will say C # cancel the pointer concept) An expression that exceeds the array boundaries is irreparable. There is no global variable or global function in C #, the overall way is implemented by static functions and static variables.

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

New Post(0)