C # initial knowledge

Source: Internet
Author: User

1. NET Framework includes three parts: The first part is the Common Language Runtime (CLR, all. NET program language common execution period component), the second part is the shared object category Library (provide all. NET program language), the third part is re-written as a component ASP. NET (the old version is asp. dll provides the objects required for ASP Web pages ). 2. c # data types can be classified into numerical and non-numerical types. numerical values can also be classified into integer and non-integer types. non-numerical values also include character and string types. 3. the naming rule of a variable must start with a letter, '_', or '@'. It cannot start with a number. The variable name cannot be the same as the keyword in C # And is case sensitive. const data type constant name = constant value is assigned when defined. values cannot be assigned elsewhere. It is often used for modifying some unchangeable variables in the program. 5. the benefit of enumeration is that it limits the value range of the variable value // defines an enumeration type enum sex: int {male = 0, female = 1} // declares an enumeration variable enum UserSex; userSex = sex. male; if we want to obtain the storage value corresponding to male, we can use (int) UserSex6. access modifier struct structure name {access modifier data type structure member ;} the advantage of using the structure is that you can store a group of correlated variables as a group by using the variable name. the member name can be accessed to avoid confusion between variables. In fact, the structure can be considered as a lightweight Class 7. after declaring an array, assign values to the data in the array one by one through the array subscript, for example, int [] age = new int [10]; age [0] = 10, age [1] = 20, of course, we can also assign int [] age = new int [10] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} or int [] Ge = new int [] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} in the last method, we didn't specify the length of the array, the system automatically determines the length of the array based on the data we provide. In addition, an array syntax int [] age = {1, 2, 3} 8. [access modifier] [static] Return Value Type method name (parameter list) {method body;} method name generally uses the pascal naming method. Method overloading: if the method name is the same, the parameter type or number of parameters are different, and the type of the return value is different, the method overloading cannot be formed. 9. an out modifier is added before the parameter to define an output parameter. Before exiting, the method must assign an out modifier to this parameter. The advantage of this parameter is that, you can use the out modifier to allow a method to return multiple values, instead of using the out modifier of a single return value. Ref adds a ref modifier before the parameter to define a reference parameter, indicating that a reference type is passed to the method, which is different from the value, operations on parameters of the reference type will affect the real parameters. For example, public static void methodA () {int a = 5; methodB (ref a);} public static void methodB (ref int number) {} methodA calls the methodB method, and pass the variable to methodB as a reference, any modification to the parameters of the methodB method squadron will affect the value of variable a in methodA. Note that if the out and ref modifiers are used in the Parameter definition of the method, when the caller calls the method, before the corresponding parameter location, you must specify the modifier params to support the parameter array and pass the variable number of parameters as a logical parameter to the method. It can be understood that this modifier automatically stores parameters in an indefinite list. When we call a method, several parameters are passed. The Compiler automatically assembles these parameters into an array, console. this parameter modifier is used in the writeline () method. Note that if this modifier is used in the parameter list of the method, this parameter must be placed at the end of the parameter list. 10. The object-oriented concept has three features: encapsulation, inheritance, and polymorphism. A class is an abstract representation of a thing with some common features: an instance of a class, that is, the embodiment of an abstract thing. Method: The action field that can be executed by the class: the status of the class, which refers to a group of related variables of the class. 11. the fields, attributes, and methods of a member access level class are called class members. They have their own access level, which is used to control how the class is accessed, access Level: The following types of public can be accessed anywhere. Only the classes that define members can access protected. Only the classes and subclasses that define them can access internal. The default modifier of the access type members of the current Assembly. the default modifier for private classes is internal12. fields and attributes to protect private data of objects, the access modifier of a field is private, so only the class that defines it can operate on this field. What should I do if other classes need to operate on this field, this requires that the attribute is an encapsulation of the field to protect the field data. You can also check the values assigned to fields to filter out the definition Syntax of non-conforming value attributes. access modifier data type attribute name {get {return field name ;} set {field name = value ;}} from the syntax, we can see that the attribute can be seen as a method with two sub-methods, but the parameter must be defined when the method is defined, the attribute is not required. Through access control of the get set Method inside the attribute, we can also set the read-only attribute to write only the attribute. By default, the modifier of the getset method is the access modifier of the inheritance and attribute. Note that the attribute does not store any data, it stores data and reads data by accessing fields. In general, attributes are mapped to a field. All data is stored in fields. Automatic attribute: When the get and set methods in the attribute do not contain any check logic, it indicates a simple assignment and value to the field, you can use automatic attributes to simplify the code access modifier data type attribute name {get; set;} when using automatic attributes, note that you cannot set read-only or write-only attributes. 13. java should be called, rather than rewriting * classes must have constructors * constructors cannot inherit! * The parent class constructor must be called in the subclass constructor. * The subclass constructor calls the non-parameter constructor of the parent class by default! * If the parent class does not have a parameter constructor, you must specify a parameter constructor to call the parent class in the subclass! Constructor is a special method of the class. It does not have to be written to void because it is automatically called when we use the new keyword to allocate objects. It is used to assign an initial value to each field of the object when instantiating a class. Each c # class will have a default no-argument constructor during definition. This constructor will assign a default value of the corresponding data type to all fields. 14. The role of inheritance lies in code reuse. sub-classes can not only access and define accessible members in the base class, but also define their own unique members. If we do not specify the parent class when defining the class, we assume that this class is derived from the Object class, and the Object class is the base class of all classes. A base class can have multiple subclasses, but a class can have only one parent class. C # does not support multiple inheritance, c # several Keywords of similar function inheritance through the concept of interfaces. this indicates that the current object is its own base: indicates its own parent class, you can use the base keyword to access members in the parent class. Sealed: This keyword indicates that the class cannot be inherited, that is, other subclasses cannot be derived. The structure in c # implicitly uses this keyword. Virtual: (virtual method) uses this keyword to modify the method, indicating that subclass can override the implementation logic of this method, in this way, the Implementation logic of the same parent class method in multiple child classes is different. override: when the child class overrides the method modified by virtual in the parent class, the override keyword must be used, indicates that this method overwrites the parent class method as: Used to quickly determine whether a type is compatible with another type. If it is not compatible, a null is returned: also used for type compatibility detection, if not compatible, a false value is returned. The mutual conversion between subclass and parent class can be implicitly converted into a parent class, but the parent class cannot be implicitly converted into a subclass. If we need to store a parent class to a subclass object, we must execute forced conversion, which may fail and cause exceptions. Therefore, before forced conversion, the programmer must control whether the parent class object can be converted into a subclass object. Classical inheritance (is-a) relational syntax class A: class B {}include/delegate inheritance (has-) the exception Handling Mechanism in class A {class B {}} 15.c# is called SEH structred exception handing. It provides A standard technology for sending and capturing runtime exceptions., and provides user-friendly error information. 4 elements of exception handling in c # (1) a class containing exception details (2) A member that raises an exception class instance (3) A piece of code block of the caller's call exception type (4) a part of the caller's code block to handle the exception that will occur 16. when using static, note that only static members can be called, but not non-static members. Non-static members can call static members and access through class name and static member name, but not through Object Name and static member name. Static classes cannot be instantiated, that is, a static Class 17 cannot be allocated using the new keyword. step 1: Define a class and related attributes to store the public class Person {public string Name {get; set;} public int Age {get; set ;}public int gender {get; set ;}ii. For an instance of a new class, set the DataContext attribute Person p1 = new Person () for the control to bind data (); // instantiate a class and assign a value to the object property, p1.Name = "AAA"; p1.Age = 18; textBox1.DataContext = p1; // set the data context of the control, textBox2.DataContext = p1; // set the data context of the Control. 3. Use Text = {binding for the control in XAML. To bind a data <TextBox Text = "{Binding Name}" Name = "textBox1" verticalignment = "Top" Width = "120"/> <TextBox Text = "{Binding Age}" Name = "textBox2" VerticalAlignment = "Top" Width = "120"/>, we will bind the values of the two attributes of the person class to the two controls, 18. the work of the INotifyPropertyChanged interface is that when we directly modify the object attributes in the background, the interface also updates the modified attributes. We need to note that when we want to implement this function, we must make our class implement this interface, that is, the definition of the person class must be modified as follows: public class Person: INotifyPropertyChanged // implements the INotifyPropertyChanged interface {private string name; private int age; public string Name {get {return name;} set {this. name = value; if (PropertyChanged! = Null) // determine whether there is a listener {PropertyChanged (this, new PropertyChangedEventArgs ("Name") ;}} public int Age {get {return age ;} set {this. age = value; if (PropertyChanged! = Null) {PropertyChanged (this, new PropertyChangedEventArgs ("Age") ;}} public event PropertyChangedEventHandler PropertyChanged;} www.2cto.com because we need to listen to the set Method of the attribute, so we can no longer use automatic attributes. We must manually write our attribute set method, if (PropertyChanged! = Null) // determine whether there is a listener {PropertyChanged (this, new PropertyChangedEventArgs ("Name");} the meaning of this code can be understood, when a listener is configured to monitor whether the attributes are changed, if the attributes are changed, the notification page will be displayed. If the attributes are changed, modify them in time. 19. The advantage of indexing is that it may improve the query efficiency, but it will occupy space and may reduce the efficiency during insert update. Create index name ON table name (field name 1 [ASC | DESC] [, field name 2 [ASC | DESC],...])

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.