A few idle words
It was really nice when I was learning LINQ.
However, after a long time, I am not so concerned about it. But friends around me always rememberI will use
Programming.
I remember learning ry in junior high school, and I had a question about the triangle edge length and the area length. I happened to know Helen's formula. When I encountered a question that could use this formula, I thought I would do it, it seems that the formula should be named after me ......
Someone asked me if I had any materials to learn about LINQ. I really couldn't tell it, because I have never systematically studied LINQ. I basically only use several extension methods of ienumerable. I want to say that I have read a few words from some versions of the X version. I will also take a look at each of them at a collection point and then take a look at their respective instructions.
Of course, more than that, I can't tell what is included in LINQ or what it is.
It is never a simple thing to define a technology.
Cause
This is the case. Someone asked me a small question today, about LINQ, And then I accidentally saw a lineCode:
Int COUNT = lst. Where (CH => Char. isnumber (CH). Count ();
The code is easy to read, that is, to find the number of digits from a char set.
The code is okay, but there is a better way to write it:
Int COUNT = lst. Count (char. isnumber );
Even if he doesn't know that the count method can pass parameters, why doesn't he write it:
Int COUNT = lst. Where (char. isnumber). Count ();
I believe that he does not know why to write CH => Char. isnumber (CH) Here, and does not know what is needed here.
This reminds me of a male colleague talking about a female colleague.ProgramApe), a girl just graduated, not very good, then the man said that the code written by the girl tostring does not contain parentheses.
This is to say that this female colleague does not know that tostring is a method, even if there is no parameter, it should be enclosed with brackets, or she does not know that tostring is a method, but it also shows that this male thinks that the method can only be called ).
Maybe the following code is simple and he will be surprised:
String [] arr = lst. Where (char. isnumber). Select (char. tostring );
Or in the event:
Delegate StringGetnumberdelegate (CharCh );EventGetnumberdelegate getnumberevent ;...This. Getnumberevent + =Char. Tostring;
Thoughts
I think most people are used to using CH => Char. isnumber (CH) because it is easy to understand, the program canRead out
. Yes, the best thing to write about LINQ is here.
For example, if you use the where method and know that the set is a char set, ch can naturally be used as each element in the char set, and then write down the judgment on each element, which is easy to understand, easy to use.
But don't be obsessed with table images and deviate from the essence.
When talking about passing functions as parameters, I remember a problem I encountered when encapsulating a calendar control: I need to color the submitted reports, unsubmitted reports, and days before:
However, the color issue has been modified many times. In the end, I simply add a func <string, color> to the encapsulated control and specify the color based on the given type (submitted or not submitted.
The last thing I want to talk about is that I didn't know how to write it.A function is also an object.
You can pass the function without knowing it, but if you write it for a question, you can simply continue writing it. I originally wanted to talk about several successive problems with the LINQ extension method. I will leave it in the next blog.
My original blog address: Starting from the count method of LINQ
Welcome to my blog: nanqi.info