C # Programming Language Study Notes (1)

Source: Internet
Author: User

C programming language and C ++ programming language have become immortal classical books, so when the long-awaited genius Anders hejlsberg writes C # programming language, I can't wait to buy a copy, but I read the comments. This book is disappointing to many people. It is a copy of msdn and there is no ideological sublimation. so I didn't buy it.
Things have been put on hold for a long time. I suddenly want to systematically learn C # And msdn. If there is no sublimation of thought, I should systematically learn the C # syntax, C # programming language is the best choice. After all, who knows C # Better than Anders?

I am reading the electronic English version of C # programming language. I am so sorry for my idol Anders, but there is no way. Who asked you to copy msdn.
I read this book through the whole article and extract it if I did not know it or thought it was different from the original one. Translate it. Fortunately, this book is easy to understand in English.
Chapter 1 Introduction
1. Note that C # itself does not have a separate Runtime Library. Instead, the. NET Framework Is The Runtime Library of C #.
C # itself does not have a separate Runtime Library, and. NET Framework is the Runtime Library of C.
2. assemblies contain executable code in the formIntermediate Language (IL) instructions, and symbolic information in the form Metadata . Before it is executed, the Il code in an assembly is automatically converted to processor-specific code by the just-in-time (JIT) compiler of. NET Common Language Runtime.
Assemblies ?) Executable in the form of IL commandsCodeAnd stores the symbolic information in the form of metadata. prior to execution, the Assembly il code will be automatically converted into code for a specific processor by. Net clr jit.
3. Because an assembly is a self-describing unit of functionality containing both code and metadata, there is no need # Include Directives and header files in C #. The public types and members contained in a participant assembly are made available in a C # program simply by referencing that assembly when compiling the program.
Assembly is a unit of Self-Describing Functions that contain code and metadata. Therefore, it is not necessary to use the # include Directive and header file in C. the public types and members contained in a specific assembly can be referenced at compilation (this specific assembly, these types and members) in C #Program.
4. forward declarations are never needed in C # because, with very few exceptions, Declaration Order is insignificant. C # does not limit a source file to declaring only one public type nor does it require the name of the source file to match a type declared in the source file.
In C #, we will never need to declare it in advance, because, except for a few exceptions, the Declaration Order is irrelevant. C # only one public type can be declared for a single source file, and the source file name does not need to match the type declared in the source file.
5. There are two kinds of types in C #:Value types And Reference types .
C #'s value types are further divided Simple types, Enum types , And Struct types , And C #'s reference types are further divided Class types, interface types, array types , And Delegate types .
C # There are two types of types,Value typesAndReference types
Value Type is further dividedSimple types, Enum types, AndStruct types and reference type are further dividedClass types, interface types, array types, AndDelegate types.
6. Five of C #'s categories of types are user-definable: class types, struct types, interface types, Enum types, and delegate types.
C # There are five types of custom types, class types, struct types, interface types, Enum types, and delegate types.
7. A delegate type represents references to methods with a special parameter list and return type. delegates make it possible to treat methods as entities that can be assigned to variables and passed as parameters. delegates are similar to the concept of function pointers found in some other versions, but unlike function pointers, delegates are object-oriented and type-safe.
Delegate type indicates a reference to a method with a specific parameter list and return type. delegates regards methods as entities, so that the method can be assigned to variables and passed as parameters. delegates is similar to function pointers in some other languages, but the difference is that delegates are Oo and type-safe.
8. Int [] Is a single-dimen1_array Int , Int [,] Is a two-dimen1_array Int , And Int [] [] Is a single-dimen1_array of Single-dimen1_arrays Int.
Int [] is a one-dimensional array of the int type, int [,] is a two-dimensional array of the int type, int [] [] is an int type, (element is) one-dimensional array (type).
I don't know what to say about this. It is estimated that we will introduce it in chapter 2.
9. Checked And Unchecked Statements are used to control the overflow checking context for Integral-type arithmetic operations and conversions.
The checked and unchecked statements are used to control integer data arithmetic operations and overflow checks during conversion.

Static   Void Main () {

Int I =   Int . Maxvalue;

Checked   {

Console. writeline (I+ 1);//Exception

}

Unchecked   {

Console. writeline (I+ 1);//Overflow

}

}

10.LockStatement is used to obtain the mutual-exclusion lock for a given object, execute a statement, and then release the lock.
Lock statement is used to obtain the exclusive lock for a given object, execute a statement, and release the lock.

Class Account

{

Decimal Balance;

Public   Void Withdraw ( Decimal Amount) {

Lock ( This ) {

If (Amount > Balance) {

Throw NewException ("Insufficient funds");

}

Balance -= Amount;

}

}

}

11.UsingStatement is used to obtain a resource, execute a statement, and then dispose of that resource.
Using statement is used to obtain a resource, execute statement, and then release the resource.

Static   Void Main () {

Using (Textwriter W = File. createtext ( " Test.txt " )) {

W. writeline ("Line one");

W. writeline ("Line two");

W. writeline ("Line three");

}

}

12. assignment to Readonly Field can only occur as part of the field's Declaration or in an instance constructor or static constructor in the same class.
The value assigned to readonly field can only occur in the following situations: As part of the field declaration, the constructor of the instance or the static constructor of the same class.
13. Parameter Array Permits a variable number of arguments to be passed to a method. A parameter array is declared with Params Modifier. Only the last parameter of a method can be a parameter array, and the type of a parameter array must be a single-dimeneter array type.
The parameter array allows a method to pass a set of variable numbers. the parameter array is declared with the Params modifier. only the last parameter of the method can be a parameter array, and the type of the parameter array must be a one-dimensional array.
14. Abstract Method is a virtual method with no implementation. An abstract method is declared with Abstract Modifier and is permitted only in a class that is also declared Abstract . An abstract method must be overridden in every nonabstract derived class.
An abstract method is a non-implemented virtual method. abstract methods are modified with abstract modifiers and can only appear in classes declared as abstract. abstract methods must be rewritten in each inherited non-extract class.
15. Indexer Is a member that enables objects to be indexed in the same way as an array. An indexer is declared like a property doesn't that the name of the member is This Followed by a parameter list written between the delimiters [ And ] . The parameters are available in the accessor (s) of the indexer. similar to properties, indexers can be read-write, read-only, and write-only, and the accessor (s) of an indexer can be virtual.
Indexer is a member that makes it possible to index objects like arrays. the declaration of Indexer is similar to that of property. Except that the member name is this [parameter], these parameters are visible in the accessors of indexer. similar to properties, indexers can read and write, read-only, and indexer accessors can be virtual functions.


Public   Object   This [ Int Index] {

Get   {

ReturnItems [Index];

}

Set   {

Items [Index]=Value;

Onlistchange ();

}

}

16. Event Is a member that enables a class or object to provide configurations. An event is declared like a field doesn't that the declaration events des Event Keyword and the type must be a delegate type.
Within a class that declares an event member, the event behaves just like a field of a delegate type (provided the event is not abstract and does not declare accessors ). the field stores a reference to a delegate that represents the event handlers that have been added to the event. if no event handlers are present, the field is Null .
An event is a member of a class or object that can send notifications. The event declaration field only contains the event keyword and the type must be delegate.
Declare an event member in the class. The event behavior is similar to the delegate type field (if the event is not abstract and the accessors are not declared ). this field stores the reference of a delegate, which is represented by the event processing that has been added to the event. if no event is processed, this field is null.
17. The notion of raising an event is precisely equivalent to invoking the delegate represented by the event-thus, there are no special language constructs for raising events.
Clients react to events through Event Handlers . Event Handlers are attached using + = Operator and removed using -= Operator.
The concept of triggering an event is exactly the same as that of calling a delegate presented by an event-therefore, there is no special construction of triggering an event.
The caller associates with the event through events handlers. Event Handlers is added with + = and removed with-=.
18. Operator Is a member that defines the meaning of applying a special expression operator to instances of a class. three kinds of operators can be defined: unary operators, binary operators, and conversion operators. all operators must be declared Public And Static .
Operator is a member that redefines the meanings of some class instances that are applied to specific form operators. Three types of operators can be defined: unary operator, binary operator, and conversion operator. all operators must be defined as public and static.
19. Destructors cannot have parameters, they cannot have accessibility modifiers, and they cannot be invoked explicitly. The Destructor for an instance is invoked automatically during garbage collection.
The garbage collector is allowed wide latitude in deciding when to collect objects and run Destructors. specifically, the timing of destructor invocations is not deterministic, and Destructors may be executed on any thread. for these and other reasons, classes shold implement Destructors only when no other solutions are feasible.
The Destructor cannot have parameters, access level modifiers, or be explicitly called. The instance destructor are automatically called during garbage collection.
The garbage collector has the right to decide when to recycle objects and run destructor. to be exact, The Destructor is uncertain during running and can be executed in any thread. for these and other reasons, the implementation of destructor should be selected when other methods are not feasible.

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.