C # Essence (version 3rd) Notes

Source: Internet
Author: User

C # Essence (version 3rd) Notes
C # Essence (version 3rd) Jump to: navigation, search

Directory
  • 1C # OVERVIEW
  • 2 Data Type
  • 3 operator and Control Flow
  • 4. methods and parameters
  • Category 5
  • 6 inheritance
  • 7 Interfaces
  • 8 value type (struct)
  • 9 type
  • 10 Exception Handling
  • 11 generic
  • 12. Delegate and Lambda expressions
  • 13 events
  • 14 support the set interface of standard query operators (New Enumerable class extension introduced in C #3.0)
  • 15. LINQ (with LINQ, you no longer need ORM; you do not need to write a set of code to process filtering classes; you can query and filter data in a concise and elegant manner)
  • 16. Custom set
  • 17 reflection, features, and Dynamic Programming
  • 18 Multithreading
  • 19 synchronization and other multi-thread processing modes (TPL)
  • 20 platform interoperability and insecure code
  • 21 Appendix: CLI
  • 22 Appendix: download and install (. NET and Mono)
  • 23 Appendix: System. Collections. Concurrent
  • 24 Appendix: C #2.0 3.0 4.0 subject
  • C # overview c # keywords :... add * alias * ascending * base by * descending * dynamic * equals * from * get * global * group * let * var * value * yield *... e.g. 1.0 --> 2.0: Yield returnUse the keyword as a local variable: @ returnCIL and ILDASM data type decimal: 1.2345m @ "... // \\\..." int? A = null; // C # 2.0int [,] cells;. Length attribute. GetLength (0) Get the 1st-dimension Length staggered array: int [] [] cells2 ;//! Operator and control flow foreach (char c in str) {...} switch-case: string constants supported? C # Do Not Allow fall-through? But case can be connected to write C #2.0 null join: expr1 ?? Expr2; (this is? : Is it a simplification?) C # does it support preprocessing? Depends on the # region # endregion method and the using System parameter; C #4.0 optional parameters (this is generally not a feature of C ++) C #4.0 name parameters (this is only available in general scripting languages !) Exception catch sequence: From the most specific to the most general? -- Should I check the sequence of exceptions that may occur in the Code Execution Process ??? Int. tryParse (ageText, out ageVar) // hell, this is not as good as the Ruby flexible class this (= Me in VB) attribute is an explicit structure in the pencil :. property instance string Name (){. get instance string ClassA: get_Name () // reference the actually generated getter method C #3.0 object initializer set initializer: l = new List {...} This calls another constructor: Well, it is a bit similar to the C ++ member initialization list, or the Java constructor calls the C #3.0 anonymous type between them: var p = new {Name = "ABC", Age = 20}; // do not abuse it. May there be performance problems? Static constructor: static ClassName (){...} // compared with Java's static {}, the syntax is slightly cumbersome. C #3.0 Extension Method: Define a static method, simulate a member function of the corresponding class (1st parameter declarations must be subject to this limitation) -- this is only a compilation feature, stconst. readonly (Java final ?) C #2.0 Classification PartialClass {...} // The compiled classes cannot be extended to implement code into multiple files. It seems to be a compilation feature. stC # Part 1 method: must return void? The out parameter is not allowed, but can be declared in a partial class using ref, and implemented in the corresponding partial class? It's a bit like C/C ++. HA inherits custom type conversion: public static implicit operator OtherType (ThisType obj ){...} sealed class... virtual: C # by default, all methods are non-virtual (fk, which intentionally draws a line with Java ?) (It may be the design made by. net clr to be compatible with the C ++ language ...) Subclass rewrite: overridenew modifier? Override sealed // prohibit further derivative implementation; base: Call the implementation of the base class version // C # the biggest problem in the language is that there are too many keywords ??? Abstractis // Java instanceofas interface interfaceinterface A: B // do not need to distinguish extends from implements in Java; Value Type (struct) is not distinguished in Java, although there are differences in concepts such as EJB, DTO, and POJO, it can be said that C # has a clearer classification of concepts. default (int) box/unboxlock cannot be used in System. valueType? If the enum type is within the lifecycle of an object, GetHashCode () should return the same value even if the object data changes (...?) ReferenceEquals? Namespace alias qualifier: extern alias CoordPlus; csc/R: CoordPlus = cp. dll... Program. cs Terminator :~ ClassName () {Close ();...} using (RAAI): Must I implement IDisposable? C #4.0 delayed initialization: System. Lazy // Some functional programming flavor ~ Exception Handling catch with no parameters {}: A bit like catch (...) {} throw in C ++; do not throw new Exception? (The latter will reset the exception stack) checked/unchecked {} block generic Pair --> C #4.0 Tuple can handle a maximum of seven parameter constraints: class BinTree Where T: System. IComparable {... * Covariant (upcast, covariance)/inverter C #4.0 use out type parameters ( ) Enable the co-Variant C #4.0 to use the in type parameter ( ) Enable the inverter delegate and Lambda expression C #3.0 delegateC #2.0 + anonymous method: delegate (args...) {...} C #3.0 Func : In * + out {1} C #3.0 Lambda: // actually implemented using delegate ??? (Int a, int B) =>{ return a + B;} when one parameter is set, you do not need to use () Lambda expressions. {} note: lambda expressions have no type external variables ('free variable' in mathematical logic '?) Expression Tree? Check whether the delegate is null before the event multicast delegate (that is, the + = syntax of the delegate type (=> event handler) is called? And copy it to a local variable... + =: System. Delegate. Combine (? The internal implementation should be the method of JavaScript: recursive call, rather than list traversal.) The purpose of the p394 event keyword is to provide additional encapsulation, avoid canceling other subscriber's public deletegate void MyEventHandler (object sender, EventArgs a); // declare the delegate type; public EventMyEventHandler onMyEventHandler = delegate {}; // The Value assignment is disabled. The set interface of the standard query operator is supported (the new Enumerable class extension introduced in C #3.0) the p407 anonymous type is the key to C # supporting 'project' operations... IEumerable During foreach, do not modify the collection set class. IEnumerator is not supported. , But through GetEnumerator() Returns an IEnumerator. (En? A bit like Ruby ...), This ensures concurrent access to the Set (?) Current ()/MoveNext () once implemented GetEnumeratorYou can get more than 50 free extension methods (using System is required. technically speaking, the result of Where () is a monad, which encapsulates the filtering operation for a given sequence based on a given predicate. Parallel LINQ: fileList. AsParallel (). Select (... 1 OrderBy () --> get an IOrderedEnumerable --> * ThenBy () * Join * GroupBy * GroupJoin + SelectMany: implement external connection? * IQuerable : Make the custom LINQ Provider possible. (With LINQ, you no longer need ORM, and you do not need to write the collection code to process the filtering class; simple and elegant Data Query and filtering functions) e.g .... = from word in Keywords where! Word. Contains ('*') select word; // from first, similar to the XQuery syntax! From clause (This avoids repeated creation of the same object ...) From filePath in... LetFile = new File (filePath) orderby file. length, filePath select file; you can insert the group operation between the from and select results :... group word by word. contains ('*') into (continuation) groups... the custom set is in the public IEnumerator method. GetEnumerator () multiple internal times Yield return??? The compiler generates code to maintain a state machine yield break: removes iterative reflection, features, and dynamic programming System. typeobj. getType () typeof (obj); System. attribute features: (a bit like the annotation in JDK 5 ?) C # the biggest difference in CLR is that code data can be added with rich semantic tags... Dynamic Data Type: You can initiate a dynamic member method call (duck typing) p532 to implement custom dynamic Object multithreading System. threading and System. threading. tasks. NET 4.0: TPL and PLINQTask (attribute) members: IsCompletedStatusIdAsyncStateTask. currentId * ContinueWith (): Task chain? Call the Wait () of the last Task object to start the execution of the entire chain? Cancel Task: CancellationToken (actually a conditional semaphore ?) Parallel. forEach (files, (file) => {...}); threadPool. queueUserWorkItem synchronization and other multi-thread processing modes (TPL) Task. factory. startNewMonitorlock // same as Java synchronized? Avoid lock this, typeof (type), string (intern problem) System. threading. interlocked assigns a delegate to a local variable: For + =, it is no problem (assuming it is a concurrent modification to a secure data structure), but what about-=? System. threading. mutexAPM (asynchronous programming model): X () --> BeginX/EndX event-based asynchronous mode (EAP) Background Worker mode platform interoperability and insecure code P/InvokerefSafeHandleunsafe: call C ++ code? Fixed (byte * p = & bytes [0]) {...} stackalloc Appendix: CLI Appendix: download and install (. NET and Mono) Appendix: System. collections. concurrent Appendix: C #2.0 3.0 4.0 subject

    Related Article

    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.