This post was last edited by Delver_Si on 2014-11-18 19:43
Chapter 1 (C#OOP) 1..NET Framework(Equivalent.)javainjdk) 2.included2Sections: Framework Library (Toolkit),CLR(CTS,CLS) Chapter 2 (C#OOP) 1.C #Syntax: Mainly contrast withjavaThe difference (1) data type stringString:C #of"S"Lowercase and uppercase are fine, usually lowercase.javaCapitalization Boolebool:javaWritingboolean (2) variables and constants Create an implicit variable:varAlternative data types (refer to textbook examples) Define constants: Add before defining variablesconst, which means that the variable can only be assigned an initial value once and cannot be modified later (3operator, expression (andjavaSame) (4Control statements if-else(Ibid.)java) switch:1.()You can use strings to compare.javaNo way 2.eachcaseAfter that, it must be writtenbreak; javaYou don't need to write it do-while,while,for:( the samejava) foreach: C# syntax: foreach (data type element name in array or collection object) {...} Java syntax: for (data type element name: array or collection object) {...} 2.array (1The same is true for one-dimensional arraysjava, but[]cannot be written after a variable (2Multidimensional arrays2Species, one kind of samejava, another:int[,] = new int[3,3]; 2The meaning of each writing is different 3.Enumeration: is a custom data type, similar to a collection type of multiple constants (1Syntax: Definition: enum enum type name {constant 1, constant 2, constant 3,...} Declaration: enumerate the type name variable name; Initialize: Variable Name = Enumeration Type Name. constant 1; (2Defined position: inmainMethod written outside, orclassWritten on the outside 4.Data Type Conversion:Convert.ToXXXX(Any type of data); -Convert any type of data to a specified type of data Chapter 3 (C#OOP) 1Class: A computer simulates reality, describing an abstraction of a real thing, and the class is a custom composite data type Record the relevant information together for easy operation (1) class2Main members: attributes, methods (2Defined location: Generally create a new oneclassThe document is written separately or in other placesclassFiles juxtaposedclasswrite (3Definition syntax: public class name { //Properties publicstring id; publicstring name; //method public void study(){ Console.WriteLine(“I love learning”); } } 2.Object: A specific implementation of a class, describing a specific thing, which can be understood as a variable of a custom class (1Instantiated object: (Usage of the same variable.)3Steps) Class name Object name= newClass name(); Or: Class name Object name(Variable name); //Declare an object Object name= newClass name(); //Initialize this object(variable) (2Object used: Generally use the members of the object (attributes and methods) Use attribute: object name. Attribute name How to use: object name. method name (); 3.Construction method: When instantiating an object, use "newClass name()”,Class name()It is a construction method used to construct objects. (1) The construction method will be automatically generated when defining the class, which is hidden. (2) The construction method can be rewritten, and the construction method is called when the object is instantiated for example. If you want to assign an initial value to an object, you can add parameters to the construction method 4.If the initial value is uncertain, it can be implemented with overload. (Method overload: Same method name, different parameter list.)1, number;2, type;3, order) Note: (1) The construction method name is the same as the class name, and there is no return value (void is not written) (2) The hidden construction method without parameters will be overwritten after manual writing. (3) When defining a class in general, two construction methods will be used: without parameters and with parameters assigned to all attributes. 5.How to distinguish between construct method parameter names and attribute names if they are the same? this: Indicates this type of object. (Object of the current class) When specifying attributes, use this 6.Namespace: Equivalent to folders If the class is placed in a different folder (namespace), it can be done by:”Namespace name.Class name”Access It can also be written at the top of the classusingpaths, and the following classes do not need to have paths 7.Access modifiers: public: Public, available anywhere internal: The default, can be omitted, and can be used within the same namespace protected: protected, can be used between parent and child classes Private: Private, only you can use it 8.Value types and reference types (refer to the previously learnedintThe difference between array and array argument call) Value types: int, double and other eight basic data types, enums, structs (to be learned later) Reference type: array, class Note: String is special, it is a reference type, but at the same time it is a value pass 9.Packing and unpacking Bin: Converts the value type to a reference type Unboxing: Converts the reference type to a value type Chapter IV 1.refandoutKeywords: Function: Pass the variable of the value type as a reference type Writing method: Add before the physical parameter and the real parameter respectivelyref(out) Note:1.When defining a method,ref(out) is written before the parameter data type 2.When calling a method,ref(outThe real argument after cannot write constants, but only variables 3.refandoutThe difference:outThe subsequent parameter can be an uninitialized variable,refNo way 2.staticModifier: static Where to use:staticWritten in the access modifier (publicetc.). Objects used: classes, properties, methods Notes:1.staticWhen modifying a class, all the properties and methods in that class must bestaticof 2.usestaticThe properties and methods of modification are directly via the class name.attribute (class name.method) to call 3.Overloading of Methods: ReferenceswinformKnowledge points Chapter 5 1.Struct: Data type similar to a class (predecessor of a class) Definition: Same as class, putclassKeywords changed tostructThat's it Example:struct Student { public string name; public void study() {} } Differences from classes:1.Structs are value types, classes are reference types (emphasis) 2.Structs can be dispensed withoutnewInstantiation, the class must be usednew 3.Structs cannot be inherited, classes can be inherited 2.Attributes: Used to encapsulate member variables in the class (add some restrictions to members through methods) Syntax:private string name; // public string Name //Pay attention to the capitalization of the first letter { get{ return name; } // Read attributes set{ name = value; } // Write attributes } Auto Properties:3.0Edition and above functions, simpler writing Syntax:public string Name { get; set; } 3.Indexer: Used to encapsulate the members of an array variable in a class and optimize how elements are found in the array Generally write2Species indexer Syntax 1: Subscript indexer public Student this[int index] { get{ return students[index]; } set { students[index] = value; } } Syntax 2: String indexer // In general, there are only read properties, no write properties public Student this[string name] { get { Studentstu = null; foreach(Student s inthis.students) { if(s.Name == name) { stu = s; } } returnstu; } } Usage: Object name[index]or Object name[“string”] Chapter 6 1.Delegate: A delegate is a data type that can be used to store the signature of a method by a variable declared with this data type Function: The method name can be passed as a parameter Usage: 1. Define delegation public delegate return value type delegate type name (parameter type parameter 1,...); 2. Declare and instantiate delegate variables (for delegate binding method: return value type and parameter list must be consistent) Delegate type name Delegate variable name = new Delegate type name (method signature); Method signature does not () 3. Invoke delegation Delegated variable name (parameter 1,...); Features: Delegates can be bound to multiple methods”+=”,You can also undo the specified method” -=” Anonymous method: does not define a method (no method name), and directly binds the method content to the delegate 2.Event: Encapsulated delegated variable (equivalent to the relationship between attributes and member variables in a class) Usage: Premise: Define delegation //Write outside of any class 1.Define an event (i.e. declare an encapsulated delegate variable)//Written in the event source publiceventOrder type name Incident name; 2.Subscribe to events (to bind the event method) Incident name+= newOrder type name(Method Signature); //Approach for incident responders 3.Raise an event (similar to invoking a delegate)//Written in the event source Incident name(parameter1,…); Note: Incidents generally involve2Objects: Event sources and Incident responders Chapter VII 1.Inheritance: The subclass (derived class) inherits the parent class (base class), and the subclass has the attributes and methods of the parent class Syntax: (when defining a class) Subcategories:Paternal class Peculiarity:1.Single-rooted. A subclass can only inherit one parent class Peculiarity:2.Transmissibility. IfAInheritanceB,BInheritanceC, thenAalso inheritedC 2.protected:(protected) member variables or methods modified with it can only be used by itself or its subclasses 3.Construct method in inheritance: Call the parent constructor first, and then call the child class constructor Method 1: Implicit call: By default (without any specification), the subclass will call the parent class's construct method without parameters Method 2: Explicit call: Specify a construction method that calls the parent class. public Son(string name,string sex,stringcolor) : base(name,sex) { headColor = color; } 4.sealed: If your class doesn't want to be inherited, you can add that keyword 5.Rewriting methods in inheritance (override(polymorphism) Syntax: The method of the parent class is usedvirtual(or.)override) modification, subclasses can be usedoverrideRewrite it Function: Reference caselesson7 Note: If a child class inherits a parent class, then you can put a child class object in the parent class reference 6.Heavy load (overload) and rewrite (override) difference Distinguish:1。 Overloading is a class with multiple methods with the same name; Rewriting is a method in two classes (parent and child classes) with the same name. 2.The name of the overload method is the same, but the parameter list is different; The rewrite method name is the same, and the parameters are the same, usevirtualmodifying the parent method,overrideModify subclass methods Chapter 8 Abstract method: useabstractMethods of grooming 1.Abstract class: useabstractmodifier class (public abstract classClass Name) Peculiarity:1.Abstract classes cannot instantiate objects and can only be inherited by subclasses 2.If there is an abstract method in a class, then the class must be an abstract class; But defining an abstract class does not necessarily have to have an abstract method in it. 3.Abstract classes can have concrete methods (non-abstract methods) 4.When a subclass inherits an abstract class, it must implement all abstraction methods in the abstract class, unless the subclass is also an abstract class 5.Abstract classes can have construction methods, but they cannot be called by themselves, they are called to subclasses 2.Interface: Define a standard and specification with the keywordinterface, interface is a data type Note:1.The interface can only declare methods, properties, indexers, and events 2.The content in the interface is all by defaultpublic, so there is no need to add modifiers, if you write it, it will compile an error 3.Interface names are capitalized"I"Beginning 4.If a class implements an interface, then everything in the interface must be implemented, unless the class is an abstract class Peculiarity:1.Interfaces can inherit from multiple (a class can only inherit one parent class, but multiple interfaces can be implemented at the same time) 2.The inherited parent class must be written in the first position after ":", and the subsequent interfaces must be separated by "," 3.If a class implements multiple interfaces with the same method name, the interface should be implemented with a display 4.interfaces can be bound 5. The interface as a parameter, polymorphism can also be realized 3.isandasUsage is: Judge whether an object is a certain type,If it is a returntrue, if not returnfalse Example:if(c is IPrint) as: Converts an object to a certain type Example: IPrint c1 = c as IPrint; 4.The difference between abstract classes and interfaces (refer to the textbookP189)
|