C # Knowledge Point record

Source: Internet
Author: User

Used to document C # Knowledge Essentials.

Reference: CLR via C #, MSDN,

How to record: Read each book, look it over, then the second time, write your notes.

CLR: The Common language runtime (Common Language Runtime) is a common language runtime that can be used by multiple programming languages (VB, F #, and so on).

Managed module: Compile the source code will generate a managed module, he is the standard PE file. Contains: PE32 header, CLR header, IL Intermediate language.

Metadata: The CLR generates Narimoto data in addition to the IL. The metadata is always associated with the file that contains the IL code.

Assembly: is a logical grouping of one or more modules/resources. is the smallest unit of reuse, security, version control. An assembly can be either a DLL or an executable program.

Fcl:framework Class Libraries (Framework class Library) a set of DLL assemblies collectively.

CTS: A common type system that develops a formal specification describing the type definition and behavior of a system.

CLS: Common Language Specification, which defines a minimum feature set in detail. Only if this feature set is supported can the generated type be compatible with other components.

OOP: A design pattern for object-oriented programming (object-oriented programming) software, based on the three concepts of encapsulation, inheritance and polymorphism.

CSP: Component software Programming (Component software programming) OOP develops to the extreme of the product, and the code forms the component module.

Two types of assemblies

The CLR supports two assemblies: weak-named assemblies and strong-named assemblies.

They all have the same structure, including PE file, PE32 header, CLR header, metadata, Manifest table, IL.

The difference is that a strong-named assembly uses the publisher's public/private key for asymmetric cryptographic signatures. Can be deployed to any location.

Two types of deployment

An assembly can be deployed in two ways: private or global.

A private deployment refers to an application directory or a subdirectory. Weakly named assemblies can only be deployed privately.

Global deployment refers to assemblies that are deployed to some recognized locations. The CLR checks these locations when it looks for assemblies.

The CLR requires that each type is ultimately derived from the System.Object type. So each type will have a basic method.

Type safety: One of the most important features of the CLR, the runtime CLR always knows what type of object it is. Call GetType to know the exact type of the object.

Type conversions

Implicit conversions and explicit conversions. If a derived class is converted to a base class, called an implicit conversion, no action is required.

// Implicit conversions New Int32 (); // an explicit conversion Int32 i = (Int32) o;

is and as operator conversions.

is to determine whether it can be converted. can return true.

As is a simplified notation for is. Determines whether it can be converted, or returns the converted result if NULL cannot be returned.

Primitive types: The data types that the compiler supports directly are called primitive types, and the compiler automatically maps to the corresponding objects. For example, a String is mapped to System.String

Checked and unchecked primitive operations

Arithmetic operations on primitive types can cause overflow. The compiler does not check for overflow by default, and the checked operator checks. The unchecked operator is not checked.

checked {     ;       - );}

UINT i = unchecked ((UInt16) (-1));

The CLR supports two types: reference types and value types.

Reference type: From the managed heap allocation, the new operator returns the object memory address. Each initialization is memory allocated, so the efficiency becomes slower.

Value type: Generally on the thread stack, does not contain pointers. Not controlled by GC, easing the pressure on the managed heap.

Any type, called a class, is a reference type. Value types are called structs or enumerations.

The reason a value type is lighter than a reference type is that it does not have to allocate memory, is not being GC, and is not referenced by a pointer.

Boxing: Value types are converted to reference types, called boxing. Take three steps separately: 1. Allocate memory. 2. Assign a value field to the heap. 3. Return the object address.

Unpacking: A reference type converts a value type, called a unboxing. Take two steps separately: 1. Gets the boxed address. 2. Copy the values contained in the field from the heap to the instance of the stack.

Unpacking efficiency is much lower than boxing.

Hash code: Object provides gethashcode to obtain a hash code for any object.

Dynamic Primitive Type: The operation that represents an object is parsed at run time. Type safety monitoring can be bypassed.

Static voidMain (string[] args) {            Dynamicvalue;  for(intDemo =0; Demo <2; demo++) {Value= (Demo = =0) ? (Dynamic)5: (Dynamic)"A";            M (value);        } console.readline (); }        Private Static voidMintN) {Console.WriteLine ("int type {0}", N); }        Private Static voidMstrings) {Console.WriteLine ("string Type {0}", s); }

Accessibility of Members

Private can only be accessed by methods that define types or nested types.

Protected can only be accessed by definition type, nested type, derived type.

Internal can only be accessed by methods in the definition assembly

Protected internal any method access in a nested, derived, assembly.

Public can be accessed by any assembly.

Static classes: Static defines classes that cannot be instantiated. cannot be applied to structs.

A static class cannot create an instance, cannot implement any interface, can define only static members, cannot be used as a field, a method parameter, or a local variable.

Static classes always consume memory from the time the program starts. Static classes are used only when you are sure that you do not need to instantiate, inherit, and so on.

Partial classes: Partial can spread code into one or more source code.

Advantages of Partial classes: Source code control is convenient, in the same class decomposed into different logical units, code splitting.

Component version Control keywords

Abstract abstraction method, which refers to a derived type that must override and implement this member.

Virtual virtual methods, which are defined implementations, can be overridden by derived types.

Override implements an abstraction that represents a member of the type being overridden.

Sealed sealed class, cannot be overridden by derivation.

New indicates that the member has no relation to a similar member in the base class. Public new void ToString ()

C # Knowledge Point record

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.