C # Advanced Programming 9th Edition read notes (i)

Source: Internet
Author: User
Tags float double instance method

First, preface

C # Concise, type-safe object-oriented language.

. NET is a schema that is programmed on the Windows platform-an API.

C # is a design from scratch for. NET language, he can take advantage of all the new features in the. NET Framework and its development environment, object-oriented programming methods.

Component Object models COM Component object model

. NET Advantages: Face object programming, excellent design, language independence, better support for dynamic Web pages, efficient data access, code sharing, enhanced security, no impact on installation, Web services support.

. NET Framework 1.0 2002 Release

. NET Framework 2.0-to-generics support, new classes, and interfaces

. NET Framework 3.0 introduces new ways to create UI (WPF and XAML, vector-based graphics instead of pixel-based graphics)

The. NET Framework 4.0 provides dynamic language integration and a large number of new libraries for parallel programming

End Day 1 Page XIX

1th Chapter. NET Architecture

1.1 The relationship between C # and. Net

1.2 Common Language runtime

Code that the common language runtime CLR runs under CLR control is called managed code

Two phases of compilation: 1, compiling the source code into Microsoft intermediate Language Il 2, and the CLR compiling IL into platform-specific code.

1.3 Intermediate languages

Il is always compiled on the fly, called JIT compilation.

The main features of the intermediate language IL:

A, object-oriented and use interfaces

A. NET-established interface shares an idea with a COM interface: to provide a contract for a class that implements a given interface must provide the implementation of the methods and properties specified by that interface.

The real implication of language interoperability is that classes written in one language can communicate directly with classes written in another language. Especially:

² classes written in one language can inherit classes written in another language

² A class can contain an instance of another class, regardless of the language in which the two classes were written.

² a method by which an object can directly invoke another object written in another language

² A reference to an object or object can propagate between methods

² When you invoke a method between different languages, you can debug these method calls alternately in the debugger, that is, debugging source code written in different languages.

Significant differences in B, value types, and reference types

Value types: Variables store their data directly in the stack

Reference type: The variable stores only the address, and the corresponding data is found in that address stored in the managed heap

C, strong data typing

Do not allow any manipulation of the blurred data type;

Universal type Systems CTS Common Tpye System

Common Language Specification CLS Common Language specification

D, exception error handling

E. Use of features

1.4 Assemblies

Two types of assemblies: private programs and shared assemblies

1.5. NET Framework Classes

The. NET Framework 4.5 base class contains roughly the scope:

Core features provided by ²il

²windows UI Support and controls

² using Web Forms and MVC in ASP.

² data access using ADO and XML

² File System and Registry access

² Network and Web browsing

²    . NET Features and Reflections

²com Interoperability

1.6 Namespaces

1.7 created in C #. NET application

Two techniques for creating Windows Desktop Applications: Windows Forms and WPF Windows Presentation Foundation. The former simply encapsulates the native Windows space and is based on pixel graphics.

WPF is based on vector diagrams.

WPF uses XAML when it creates an application. XAML Extensible Application Markup Language Extensible application Markup Language

Declarative programming: Instead of using programming languages to create objects programmatically, all elements are declared through the programming of XML types.

WCF is a feature-rich technology that provides multiple communication options. Note that you can use rest-based communication or soap-based communication to get all the functionality that standard Web services provide.

1.8 The role of C # in the. NET Enterprise Architecture

2nd Chapter Core C #

2.4 Pre-defined data types

Value types are stored on the stack, and reference types are stored on the managed heap.

C # has 15 predefined types, 13 of which are value types, 2 are reference types string and object

Predefined integer types 8: sbyte short int long byte ushort uint ULONG

Predefined floating-point types 2: float double

Predefined decimal is not a financial calculation-specific, not a basic type

predefined bool Types:

Predefined character types: Char

Predefined reference Types 2: Object string

2.5 Flow Control

Conditional statement: If switch

Looping statements: For while Do...while foreach

Jump statement: Goto break Continue return

2.6 Enumeration

An enumeration is a user-defined integer type that, when declaring an enumeration, specifies an acceptable set of values that an instance of the enumeration can contain.

End Page 46

2.7 Name space

2.8 Main () method

2.9 More about compiling C # files

2.10 Console I/O

2.11 Using annotations

2.12 C # Preprocessor directives

The command of the preprocessor directive does not translate into commands in executable code, but it affects all aspects of the compilation process.

2.13 C # Programming rules

3rd Chapter objects and types

3.1 Creating and using classes

3.2 Classes and structures

Classes and structs are templates that create objects, each of which contains data and provides methods for processing and accessing the data.

The difference between classes and structs is how they are stored in memory and how they are accessed. Class is a reference type that is stored on the heap heap. A structure is a value type that is stored on a stack stack. The structure does not support inheritance. Using structs for smaller data types can improve performance.

Class 3.3

End Page 79

3.4 An anonymous type is a class that inherits only from object and does not have a name

3.5 structure

Structs are always derived from system.valuetype,system.valuetype derived from System.Object.

Structs do not support inheritance; no arguments are allowed; You can specify how fields are laid out in memory.

Structures are primarily used for small data structures. However, when passing a struct as a parameter to a method, it should be passed as a ref parameter to avoid performance loss-only the address of the structure in memory is passed.

3.6 Weak References

Weak references allow objects to be created and used, but when the garbage collector runs, objects are reclaimed and memory is freed. Created using the WeakReference class.

3.7 Parts Category

The partial keyword allows a class, struct, method, or interface to be placed in multiple files.

3.8 Static Classes

A static class is functionally the same as a class created with a private static function, and cannot create an instance of a static class. Calls to static classes can be made using the type name.

3.9 Object class

All of them. NET classes are derived from System.Object.

3.10 Extension methods

An extension method is a static method, which is part of a class, but is not actually placed in the source code of the class.

4th Chapter Succession

4.1 Inheritance

4.2 Types of inheritance

Implementation inheritance: Represents a type that derives from a base type that owns all member fields and functions of that base type.

Interface Inheritance: Indicates that a type inherits only the signature of a function and does not inherit any implementation code.

Structs are always derived from System.ValueType, and they can also derive from any number of interfaces.

Classes are always derived from System.Object or another class that the user chooses, and they can also derive from any number of interfaces.

4.3 Implementing inheritance

If a method with the same signature is declared in both the base class and the derived class, but the method is not declared separately as virtual and override, the derived class method hides the base class method.

The special syntax in C # is used to invoke the base class version of a method from a derived class:base<methodname> ()

C # allows classes and functions to be declared as Abstrac. Abstract classes cannot be instantiated, and abstract functions cannot be implemented directly, and must be overridden in non-abstract derived classes.

C # allows classes and methods to be declared as sealed. For a class, it means that the class cannot be inherited, and for a method, it cannot be overridden.

The order in which the constructors are called is to call System.ojdect first, and then proceed from top to bottom in the hierarchy until the class to which the compiler is instantiated is reached.

4.4 Modifiers

Public protected Intermal Private

New static virtual abstract override sealed extern

4.5 Interface

Declaring an interface is syntactically identical to declaring an abstract class, but does not allow the implementation of any member of the interface. In general, interfaces only contain declarations of methods, properties, indexers, and events.

An interface cannot be instantiated, it contains only the signatures of its members. An interface can have neither a constructor nor a field.

It is not allowed to declare modifiers about members in the interface definition. Interface members are always public and cannot be declared as virtual or static.

End Page 119

5th Chapter Generic Type

5.1 Generic Overview

Generics can create classes and methods that are independent of the containing type.

Generic classes use generic types, and you can replace generic types with specific types as needed, guaranteeing type safety.

Generic class, generic interface, generic method, generic delegate.

Value types are stored on the stack, and reference types are stored on the heap. C # classes are reference types, and structs are value types.

A reference type shares all the same implementation code for the same local class, because a reference type can reference a reference type if it requires only 4 bytes of memory address (32-bit system) in the instantiated generic class. Value types are contained in the memory of the instantiated generic class, and because each value type has a low memory requirement, a new class is instantiated for each value type.

5.2 Creating a generic class

5.3 Generic class

Default: Generic default is used to initialize a generic type to null or 0, depending on whether the generic type is a reference type or a value type.

Constraints: If a generic class needs to invoke a method in a generic type, you must add a constraint.

Inheritance: A generic type can implement a generic interface, or it can derive from a class.

A generic class can derive from a generic base class, which requires a generic type that must repeat the interface, or a type that must be specified for the base class.

Static members: Static members of a generic class can be shared only in one instance of the class.

5.4 Generic interface

. NET 4 Adds an important extension through covariant and anti-change to generic interfaces and generic delegates.

Covariant and anti-change refers to the conversion of the type of the parameter and the return value.

The parameter type is covariant, and the return type of the method is immutable.

If a generic type is labeled with an out keyword, the generic interface is covariant.

If a generic type is labeled with the IN keyword, the generic interface is immutable.

5.5 Generic Structure

5.6 Generic methods

6th Chapter Array

6.1 Multiple objects of the same type and different types

Multiple objects of the same type can use collections and arrays. Tuple tuple types can be used for multiple objects of different types.

6.2 Simple arrays

An array is a reference type, so when an array is declared, it must be allocated memory on the heap.

After you specify the size of the array, you cannot resize the array if you do not copy all the elements of the array. You can use a collection if you do not know beforehand how many elements in the array should be included.

6.3 Multi-dimensional arrays

6.4 Jagged arrays

End Page 139

6.5 Array Class

Declaring an array with square brackets is a notation for using the array class in C #.

Using C # syntax in the background creates a new class derived from the abstract base class array.

The array class is an abstract class, so you cannot use constructors to create arrays.

If the element of the array is a value type, copying the array copies all values.

If the element of the array is a reference type, the element is not copied and only the reference is copied.

6.6 Array as parameter

Arrays support covariance, which means that an array can be declared as a base class whose derived type elements can be assigned to an array element.

Array covariance can only be used for reference types and not for value types.

Arraysegment<t> represents a segment of an array that contains information about an array segment (offset and number of elements).

The array segment does not copy the elements of the original array, but the original array can be accessed through arraysegment<t>. If the elements in the array segment change, the changes are reflected in the original array.

6.7 Enumeration

Using enumerations in a foreach statement, you can iterate over the elements in the collection without knowing the number of elements in the collection.

An array or collection implements the Ieumerable interface with the Geteumerator () method. The Geteumerator () method returns an enumeration that implements the Ieumerable interface, and then the foreach statement can iterate over the collection using the Ieumerable interface.

The yield statement is used to create an enumerator. The yield return statement returns an element of the collection and moves to the next element. Yield break to stop the iteration. The method or property that contains the yield statement is also known as an iteration block, and the iteration block must be declared to return a IEnumerator or IEnumerator interface, or a generic version of those interfaces. This chunk can contain multiple yield return statements or yield break statements, but cannot contain return.

6.8 tuples

The. NET framework defines 8 generic tuple classes and a static tuple class that they use as a factory for tuples.

6.9 structure Comparison

7th operator and type casts

7.1 Operator and type conversions

7.2 operator

7.3 Types of security

7.4 Comparing the equality of objects

End Page 169 Start October 8, 2017

7.5 Operator Overloading operator

C # requires that all operator overloads be declared public and static.

C # requires that you have a pair of overloaded comparison operators, and you must return a value of type Boolean. = = and! = > and < >= and <= three pairs.

7.6 User-defined type casts

Implicit implicit casts, explicit explicit casts

C # requires that the definition of a type cast be placed inside the source class (or structure) or the target class (or structure).

End Page 189 Start October 9, 2017

8th delegate, lambda expressions, and events

8.1 Reference methods

A delegate is a type-safe class, and she defines the type of the return type and the parameter.

The delegate contains not only a reference to the method, but also a reference to the method.

8.2 Delegates

In C #, a delegate is always syntactically accepting a constructor for a parameter, which is the method of a delegate reference. This method must match the signature when the delegate was originally defined.

To reduce the amount of input, only the name of the address can be transferred, as long as the delegate instance is needed, which is called a delegate push. This C # feature is valid as long as the compiler can parse the delegate instance into a specific type.

An instance of a given delegate can reference an instance method or a static method on any object of any type-as long as the signature of the method matches the signature of the delegate.

The generic Action<t> delegate allows methods that call void to return a type.

A generic func<t> delegate allows a method to be called with a return type.

Multicast delegates: Multiple methods are called consecutively sequentially, and the signature of the delegate must return void.

8.3 lambda expression

8.4 Events

Chapter 9th string and Regular expressions

9.1 String

9.2 Regular Expressions: A language dedicated to string processing, a set of escape codes that identify character types.

10th Chapter Set

10.2 Integrated Interfaces and types

10.3 List List<t>

10.4 Queue FIFO queue<t>

10.5 Stack LIFO stack<t>

10.6 Linked list bidirectional linked list linkedlist<t>

10.7 ordered list sorts the desired collection based on the key sortedlist<tkey,tvalue> class

The 10.8 Dictionary is also known as a map or hash table to quickly find values based on keys didtionary<tkey,tvalue>

Lookup<tkey,telement> sorteddictionary<tkey,tvalue>

10.9 Set hastset<t> unordered list of non-repeating elements sortedset<t> an ordered list of elements that do not repeat

10.10 Observable Set observablecollecton<t>

10.11-bit array

Bitarry class reference type, you can reset the size

The BITVECTOR32 structure value type is stack-based and fast.

10.12 Immutable Set Immutable.collections

10.13 Concurrent Collection Collections.concurrent

10.14 Performance

End Page 286

Chapter 11th LINQ

11.1 LINQ Overview Language Integration queries Language Integrated query

The query expression must begin with a FROM clause and end with a select or a group clause, where you can use the where, by-order, join, let, and other from clauses between the two clauses.

When you define a query expression during run time, the query does not run, and the query runs when the data item is iterated.

11.2 Standard Query operators

Where () passes the second parameter index, which is the counter for each result returned by the filter.

OfType () type-based filtering

GroupBy ()

11.3 Parallel LINQ

11.4 Expression tree

11.5 LINQ Provider

The 12th Chapter Dynamic Language extension

12.1 DLR Dynamic Language Runtime Language runtime

12.2 Dynamic type allows you to write code that ignores type checking during compilation

There are two restrictions on the type of dynamic. The dynamic object does not support extension methods, and the anonymous function lambda expression cannot be used as a parameter to a dynamic method call, so LINQ is not available for dynamic objects. Most LINQ calls say extension methods, and lambda expressions are used as parameters for these extension methods.

12.3 includes DLR Scriptruntime

12.4 DynamicObject and ExpandoObject

End Page 332

The 13th chapter asynchronous programming

13.1 Importance of Asynchronous programming

The most important improvement of c#5.0 is to provide more powerful asynchronous programming. Two new keywords added: Async and await.

The method call for asynchronous programming is run in the background (usually with the help of a thread or task) and does not block the calling thread.

Three asynchronous programming in different modes: Asynchronous mode, event-based Asynchronous Pattern, task-based Asynchronous Pattern tap.

The new task-based Asynchronous Pattern tap is implemented using the ASYNV and await keywords.

13.2 Asynchronous Mode

The async pattern defines the BeginXxx method and the EndXxx method. The BeginXxx method accepts all input parameters of its synchronous method, the EndXxx method uses all the output parameters of the synchronous method, and returns the result by the return type of the synchronous method.

When using asynchronous mode, the BeginXxx method defines a Asynccallbak parameter that accepts a delegate that is called after the asynchronous method execution completes. The BeginXxx method returns IAsyncResult, which verifies that the call has been completed and waits until the execution of the method has ended.

Event-based Asynchronous programming defines a method with an async suffix. When the Async method finishes, it does not define the delegate to invoke, but instead defines an event.

Task-based Asynchronous programming defines a method with an async suffix and returns a task type. However, you do not need to declare a variable of the task type to set the result returned by the method. Just declare a variable of type string and use the await keyword. The await keyword relieves the thread of blocking and completes other tasks.

13.3 Basics of Asynchronous programming

The async and await keywords are just compiler features. The compiler creates code with the task class.

The async modifier can only be used with methods that return a task or void, not in the entry point of a program, where the main method cannot use the async modifier. An await can only be used to return a task method.

A combo: A combination can accept multiple parameters of the same type and return a value of the same type, and multiple parameters of the same type are combined into one parameter to pass. The Task assembly accepts multiple task objects as parameters and returns a task.

13.4 Error Handling

13.5 Cancel

Chapter 14th memory Management and pointers

14.1 Memory Management

14.2 Background Memory Management

The stack store is not a value data type for an object member. The stack is padded down, which is populated from a high memory address to a low memory address.

The stack pointer represents the address of the next free storage unit in the stack.

14.3 Releasing unmanaged Resources

When you define a class, you can use two mechanisms to automatically release unmanaged resources. One is to declare a destructor or finalizer as a member of the class. The other is to implement the System.IDisposable interface in the class.

14.4 Unsafe Code

15th Chapter Reflection

15.1 Processing and checking code during run time

Custom attributes allow you to associate custom metadata with program elements that are created during compilation,

and embedded in the assembly.

Reflection is a common term that describes the function of checking and handling program elements while running.

15.2 Custom Features

The attribute class attribute itself is marked with an attribute--system.attributeusage attribute.

AttributeUsage is more like a meta attribute because it can only be applied to other attributes and cannot be applied to a class.

15.3 Reflection

System.Type: Access information about any data type.

System.Reflenction.Assembly: Accesses information about a given assembly or loads an assembly into a program.

There are three ways to get a type reference to any given type, as follows:

Typeof (given type) type t= given type. GetType () type T=type.gettype (given type)

Type is the gateway to many reflection functions, implementing many methods and properties.

16th. Errors and exceptions

16.1 Introduction

16.2 exception Classes

16.3 Catching exceptions

16.4 user-defined exception classes

16.5 caller Information

End Page 418

C # Advanced Programming 9th Edition read notes (i)

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.