Let's review. NET in these days

Source: Internet
Author: User

today is our third day to review the previous study, but also today we ended the review. Before school time feeling knowledge is all obscure, seldom used in life, so like to repeat the memory, and now the knowledge of learning is now and even the future, we use every day, so it is not necessary to repeat the memory, as long as I remember the existence of knowledge points will be remembered to the specific content, But today's review I found that the practice is still wrong, it may just start, too many things are hard, so I want to pass this article to pick up again I forget, hey. The following is the specific easy to forget and do the problem is more blunt it.

I. Constructors

The constructor method name, like the class name, has no return value, not even void. the constructor can have parameters, the new object passes the function arguments, and if the constructor is not specified, the class has a default parameterless constructor. If a constructor is specified, there is no longer a default parameterless constructor, and you need to write it yourself if you need a parameterless constructor. constructors can be overloaded, which means that there are multiple constructors with different parameters. I know how to write the constructor in the course of learning, but forget that there is "base" this keyword can inherit the argument, just remember in the output time can be used, so now to summarize the next, hey, the following to write a question to deepen my memory.

Define Father Class father (surname LastName, property, Blood type Bloodtype), son sons class (play game PlayGame method), daughter daughter Class (Dance Dance method), call the parent class constructor (: Base ( ) assigns a value to the subclass field.

//Define Father Class father (surname LastName, property, Blood type Bloodtype),    classFather { PublicFather (stringLDoublePstringb) { This. LastName =l;  This. property =p;  This. Bloodtype =b; }        stringLastName;  Public stringLastname {Get{returnLastName;} Set{LastName =value;} }        DoubleProperty ;  Public DoubleProperty {Get{returnProperty ;} Set{property =value;} }         stringBloodtype;  Public stringBloodtype {Get{returnBloodtype;} Set{Bloodtype =value;} }    }
 //daughter daughter Class (Dance Dance method),    classDaughter:father { PublicDaughter (stringLDoublePstringb):Base(l,p,b) {} Public voidDance () {Console.WriteLine ("My name is {0}, my blood is {1}, there is {2} property, and I Can Dance",Base. Lastname,Base. Bloodtype,Base.        property); }    }
 //sons son class (play game PlayGame method),    classSon:father { PublicSon (stringLDoublePstringb):Base(l,p,b) {} Public voidPlayGame () {Console.WriteLine ("My name is {0}, there is {1} property, my blood is {2}, and I will play the game \ n",Base. Lastname,Base. property,Base.        Bloodtype); }    }
classProgram {//Call the Parent class constructor (: Base ()) to assign a value to the subclass field        Static voidMain (string[] args) {Son s=NewSon ("greatly",7829392,"A");            S.playgame (); Daughter D=NewDaughter ("Laugh and smile",2793178062,"B");            D.dance ();        Console.readkey (); }    }

in this question there is a parent class father, he has three attributes have been used in the form of a constructor, and in the son and daughter also exist these properties Ah, can inherit, but at this time can be used in the constructor directly in the base of the parameter, very convenient, this little knowledge point to do the time I ignored, And that time to read the time, thought it was just in the son daughter of each method output time using the keyword, hey.

Two. Virtual methods and abstract methods

some points to note about virtual methods:1. If there are methods in the parent class that need to be overridden by subclasses, you can mark the method as virtual2. The virtual method must have an implementation in the parent class, even if it is an empty implementation. 3. Virtual method subclasses can be overridden (override), or they can not be overriddensome points to note about abstract methods:1. Need to mark with the abstract keyword2. Abstract methods cannot be implemented in any way. 3. Abstract members must be included in the abstract class. 4. Because the abstract member does not have any implementations, the subclass must override the abstract member. 5. Abstract classes cannot be instantiated, the role of abstract classes: the role of abstract classes is to let subclasses inherit. 6. Abstract classes can include abstract members, which can include members with specific code. 7. There are also abstract methods that cannot be modified with staticIn summary , the virtual method and abstract method is not now can not write, but feel can not distinguish what time use virtual method, what time use abstract class, a lot of the functions of the abstract class implementation of the use of virtual method is also possible to achieve, this is a little confused. In fact, like the blog I wrote a few days ago a factory pattern of a practice, the inside of the shape is a parent class, and he is an abstract class, do not need to implement its methods, but in which write a virtual method can also be achieved, so did not find their differences. three. Interface • 1. The interface can only contain methods (properties, events, indexers are also methods)• 2. The members in the interface cannot have any implementations. Say no to do• 3. The interface cannot be instantiated. • 4. Members in an interface cannot have any access modifiers. (default to public)• 5. Subclasses that implement an interface must implement all the members of the interface. • 6. Subclasses Implement interface methods, do not need any keywords, directly implemented. • 7. The meaning of the interface exists for polymorphism. interface Learning is still relatively simple, here to review the time to forget the 4th, its default modifier is public, because the interface is used to implement its methods, so the default modifier must be public. Four. Static and non-static static: Use the keyword static, call method time can only be called with the class name, Access static members in a static method, do not directly access the instance members, pre-call initialization. non-static: No keyword static is required, calling method time can instantiate an object, invoke a method with an object (that is, initialize an object), access an instance member in an instance method, or access a static member. in reviewing this time how to put these knowledge points to forget, before the memory is very clear, now suddenly think of it but feel strange, or use less bar, next I will be in time to review, hey, can not do so, study finished, many and forget.

Five. Handling of strings

the processing of strings is still a problem to use, but a lot of the method that Microsoft provides to me, but I do not call the method, but in the string character type conversion above always do not know which type is better, or should be converted to that type, the following simple example to say.

Static voidMain (string[] args) {            #regionMyregionstringnum ="I Love You"; stringArray = num. Substring (0,1).            ToLower (); stringArray1 = num. Substring (2,4); stringArray2 = num. Substring (5); vararr =Array. ToCharArray ().            Reverse (); varARR1 =array1. ToCharArray ().            Reverse (); varARR2 =array2. ToCharArray ().            Reverse (); foreach(varItemincharr) {Console.Write ("{0}", item); }            foreach(varItem1incharr1) {Console.Write ("{0}", item1); }            foreach(varItem2incharr2) {Console.Write ("{0}", ITEM2); } console.readkey ();

like the above problem, every time you do this type of question, always do not know how to change its type, in fact, this is the problem of yesterday, in doing this problem time wasted a long time ah, this in front of those several types of conversion above tangled Ah, Until today I think of it. We often think of the Var keyword, replaced it, feel a lot easier, no more tangled type conversion that use which is good, but also know in the time of doing the question will use the hint what type, but in this respect is not very well mastered.

six. Collection        

Collection Common operations Add, traverse, remove,namespace System.Collections1.ArrayList variable-length array, using an array-like,attribute Capacity (the number of elements that can be accommodated in the collection, doubling);count (the number of elements actually stored in the collection. )? Method:? Add (); AddRange (Icollection c); Remove (); RemoveAt (); Clear ();? Contains (); ToArray (); sort (): sort; Reverse (): Invert. A collection of 2.Hashtable key-value pairs, similar to a dictionary, Hashtable fast when looking for elements.           ? Add (object key,object value);? hash["Key"]? hash["Key"]= "modified";?. ContainsKey ("key");? Remove ("key");? Traversal:? Hash. Keys? Hash. Values/dictionaryentry3.list<t> is similar to the upgraded version of Arraylist,arraylist. Various methods: Sort (), Max (), Min (), Sum () ...4.dictionary<k,v> is similar to the upgraded version of Hashtable,hashtable. in the review to set this piece of time, ArrayList and list is still very familiar with, and his several methods feel not strange, but in dictionary and Hashtable time on a lot of unfamiliar, his value through key to obtain, this use of perhaps very little, But it does feel a lot of trouble, and it's not all used to do practice time. Therefore, we should be proficient in the specific method.
Seven. File Class File : Manipulate files and manipulate files as a whole. Copy, delete, cut, etc., is a static class;   Directory : Operation directory, refers to the folder, static class;path: The directory or path to the file operation, but here the file directory or path is not actually present, that is, for the processing of strings;Stream: The file stream, where it is an abstract class. FileStream: He is a file stream;StreamReader and Streamwrite;file class simply say these, before I have their own commonly used methods thanked, but just know these methods, file class is I think the least clear to do the idea of the problem, do not know the parameters too many problems, or just start contact sensitive to it, do this feeling is very distressed ah, This also need to have a good grasp of, before this did not do familiar with, this is my basic reason, next to look at the method, the specific use of this exercise. Ah, feel a process of review let me know where I have not mastered, I have to learn to revisit the basic knowledge of the previous study. Feel forget the good fast, in short, this review let me see clearly again the situation of their own study, while the timely review and exercise exercises can help us to strengthen the knowledge amount, hey, OK, today summed up here.

Let's review. NET in these days

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.