C # Basic Notes

Source: Internet
Author: User
Tags array definition

1. C # variable naming can begin with the Mail character @
2, the string value in C # can start @, so that the string is a verbatim string, two double quotation marks of any word nonalphanumeric as a string processing, special characters do not need to escape, but double quotation marks are required, otherwise it will be treated as the end of the string. such as: "ASDASD:item1item2 "
3. C # supports GOTO statements
4. The switch statement in C # does not allow the execution of the next case to enter the execution statement from the executing statement of one of the cases, so you must add a break after the statement for each one to interrupt execution, even if the default needs to be added. An exception is when multiple cases are stacked together and then added to the execution statement, which is possible (you cannot enter one case first and then another).
A result type of 5, two short type number multiplication is int.
6, the array in C # is divided into matrix arrays and jagged arrays, arrays of matrices are neat, each row has the same number of elements, and jagged array This allows each row to have a different number of elements, that is, an array of arrays. matrix Array Definition: int[,] arr = new int[3,4]jagged Array Definition: Cannot initialize this: int[][] arr = new Int[3][4],you can int[][] arr = new int[3][], then define the sub-array: arr[0] = new int[3]; arr[1] = new Int[4]or int[][] arr = new int[2][] {new int[] {}, new int[] {1}}or int[][] arr = {New int[] {i}, new int[] {1}}this jagged array of C + + cannot be implemented, but Java can be implemented.
7. The delegate keyword for C # is the definition of a delegate variable that defines a function with the same parameters and the return value type as delegate, which can actually be understood as a function type, thereby using a delegate variable to invoke functions of the same type but with different functions.
8, the object-oriented C #,inheritance is also a single-inheritance multi-implementation.
9. C # variables are classified as value types and reference types, and simple types (int, etc.) are mostly value types, whereas string, array, and class instances are reference types; it's worth noting that struct types are also value types, although they look like classes.
10. The classes defined in C # are internal by default, or can be specified using the Internal keyword display, which is the only code in the current project that is accessible to the inner class. For code in other projects to be accessible, you need to add the keyword public when you define it. You can also define classes as abstract classes (using the keyword abstract. cannot be instantiated, but can be inherited, can have abstract members),You can also define a class as sealed (using the keyword sealed, cannot be inherited)In C # class definitions, the accessibility of a derived class (public or internal) cannot be higher than the base class.
A class in C # can be static, and it is statically class, where all members must be static and cannot be initialized with a new instance, and can have a static constructor. Static constructors are called automatically when static methods of a static class are called (and are called only once). Reference: http://blog.csdn.net/xiaobai1593/article/details/7278014
11, the interface definition uses interface, its accessibility definition similar, the default is internal. However, the interface definition cannot use the abstract and sealed keywords, and these two keywords have no meaning to the interface.
12, the class will call the constructor at initialization, you can use the This keyword to invoke other constructors of the class, use the base keyword to invoke the different constructors of the base class, and thus construct a more complex sequence of constructor execution.
13. There are three types of class members in C #: Fields, Methods, and properties, which can be decorated with public, private, internal, and protected. Without a keyword decoration, the access level defaults to private, and protected internal members can be defined so that it can only have code access to derived classes in the project. about field Definitions:(1) When defining a field, you can use the keyword readonly adornment, so that the field can only be initialized during the execution of the constructor orAssign Value(2) A field can be static, or static, and a const member is static, and a const member cannot use the static modifier
about the definition of a method:(1) The method definition can be modified using virtual, which means that the method can be overridden by the quilt class; subclasses are overriding The method must also use theOverride modifier overrides method. When overriding a method with override, you can use the sealed adornment the overriding method cannot be overridden by its subclasses, and note that the sealed adornment method can only be used with override. (2) abstract, which can only be used in an abstract class, must be overridden in a non-abstract subclass and still require the override keyword(3) You can use the extern keyword to place the method definition somewhere else outside
about attribute definitions: reference http://www.jb51.net/article/48324.htmThe most important difference between a property and a field is that the property has two function blocks (accessors), get and set blocks, can get and modify the property's value, can control the access level of the property, and the get block and set block can also have their own accessibility, but its accessibility cannot be greater than the accessibility of the property. properties can also add virtual, abstract, override, and sealed keyword adornments, but fields cannot.
14, you can use the New keyword to decorate the child class in the same way as the parent class (the implementation of the method is different, and the parent class can not use the virtual decoration, the method in the subclass must not use the override adornment), the display of the hidden parent class in the method, You can also use the new keyword without creating a warning.
15, similar to Java, C # also has a keyword that represents the parent class object and the child class object. In the code of the subclass, base represents its parent class object, and this represents the subclass object itself.
16. Interface defines an interface, an important difference between an interface member and an ordinary class member:(1) All members in the interface are public, and access modifiers are not allowed(2) interface members cannot contain code bodies (3) interface members cannot have fields(4) interface members cannot use static, virtual, abstract, or sealed-modified definitions because they do not require(5) You cannot nest defined type members inside an interfaceinterfaces can inherit interfaces, and if you want to hide the parent interface, use the New keyword
17, C # code can use #region XXX various code #endregion来对代码分组折叠
18, support partial keyword to do some class definition, you can put a definition of a class in different files, only need to add a partial keyword to the class definition of each file to modify class. Part of the class can also contain some methods, that is, the definition and implementation of the method in different places, you need to add the partial keyword before the method.
19, the advantage of the collection compared to the array is that the size is longer, you can control access to the containing object, search and sorting, and so on.
20, can implement the ICloneable interface to make deep copies of objects.
21, the simple type variable can be sealed into an object or an interface, you can also be unboxing forced type conversion back. The IS and as operators involve the ability to marshal and unboxing, is to determine whether a type is another type, and as is to convert one type to another type.
22. There is a double question mark operator in C #:??, this operator is the processing of nullable variables:OP1? op2 and OP1 = = Nulll Op2:op1 have the same effect.
23. C # The generic strongly typed collection classes in the System.Collections.Generic are under the namespace, of course, there are many non-strongly typed collection classes under System.Collections, and these collection elements are object types when they are fetched, and need to be cast to be used, and generic is not required for the collection below.
24, when defining a generic class, it is important to note that the generic t may be a value type or a reference type, which is a value type which cannot be assigned null, so you can use the keyword Default,default (t) to get null or 0 based on the actual type of T.
25. The Dynamic keyword can define a dynamically typed variable and not determine the actual type of the variable. However, this is only a compile-time existence and will be replaced with the System.Object type during runtime. A dynamic variable produces an exception if it accesses a member that does not exist.

C # Basic Notes

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.