Using the work time to make a note, I do not know the leadership will not see, there may be colleagues see also said:)
As for the nullable type, there is no such concept in c#1, introduced in C#3. So, for example, do we want to make a representation of human beings, who have names and ages, and how do they represent a person who is not old?
General practice will be a person int type sealed into a reference type, some of the people used in the membership, the type of the category is just sealed reference type, as follows
1 Public class Person2 {3 Private stringname;4 Privatepersonage age;5 6 PublicPerson (stringname, personage age)7 {8 This. Name =name;9 This. Age =Age ;Ten } One A } - - //using a single reference package in C#1 the - Public classpersonage - { - Public intAge ; + Public BOOLHasage; -}
It is to be judged whether there is an age, if the person has a case p, to determine whether the P-image of the private age of the hasage is true,true for age, and vice versa. This will obviously introduce a large number of unwanted types, and there are functions that are re-usable, representing a type of bool of a label. The introduction of the nullable type in the C#3, the way to add a nullable<t> structure, is that it should be the same as our personage, but now this system implicitly supports it.
1 Public classPerson12 {3 Private stringname;4 Private int?Age ;5 6 PublicPerson1 (stringNameint?Age )7 {8 This. Name =name;9 This. Age =Age ;Ten } One}
Combining the optional and implicit parameters provided in C#4, you can use NULL to initialize the age value, when it is necessary to determine whether a person is an age or not, just to determine whether the private age of P is null .
1 Public classPerson22 {3 Private string?name;4 Private int?Age ;5 6 Public string? Name {Get{returnName }Set{name =value;} }7 Public int? Age {Get{returnAge }Set{age =value;} }8 9 Ten PublicPerson2 (string? Nameint? Age =NULL) One { A This. Name =name; - This. Age =Age ; - } the}
To be judged in the entrance category.
1Person2 P2 =NewPerson2 (NULL,NULL);2 3 //You can use the "?" The value of NULL to determine whether there is a name and age4 5 if(P2. Age = =NULL)6 {7Console.WriteLine ("This person has no age!!!");8 }9 Ten if(P2. Name = =NULL) One { AConsole.WriteLine ("This person has no name!!!"); -}
as a result, you can use NULL to make a value by remembering to add a "?" to a non-quoted type. such as int? A=null, short? B=null ...
Below is the LINQ (Language Integration Enquiry), which re-writes a book category, as follows
1 Public class Book2 {3 Public stringAuthor {Get;Set; }4 Public intPageSize {Get;Set; }5 6 PublicBook (stringAuthorintpageSize)7 {8Author =author;9PageSize =pageSize;Ten } One A Public StaticList<book>getbooks () - { - return NewList<book> { the NewBook ("Fish0", -), - NewBook ("Fish1",1800), - NewBook ("Fish2",2800), - NewBook ("Fish3",3800), + NewBook ("Fish4",4800), - NewBook ("Fish5",5800) + }; A } at}
The entry page uses the following
1 class Program2 {3 Static voidMain (string[] args)4 {5 6list<book> list =book.getbooks ();7 //Select books with more than 1000 pages and print8 9 varmatching = fromBook BinchListTen whereB.pagesize > - One Selectb; A foreach(varMinchmatching) - { -Console.WriteLine (M.author +" "+m.pagesize); the } - - Console.readkey (); - } +}
The key word that is often used in conjunction with LINQ, I think is Var, because I want to make the editor to judge what type, this is the invisible type, save some complicated type input. LINQ's language and SQL are almost identical, and the cost of learning is small, and the join, order by, and group by in SQL can be found in C # LINQ.
With other ORM frameworks such as EF, using LINQ can greatly reduce the amount of code, and many of the inquiries are deferred, not all at once, and then from the screening, but by LINQ to SQL, and then to the repository for enquiries.
Please treatise.
02.c# nullable type, default parameters, LINQ (Chapter 1.3-1.4)