Lynch is A junior in the Computer Science Department of A university in A city. He has no hobbies except playing computer and playing basketball. He is used to surfing the Internet in his dormitory and has average academic performance. Li Qiu, a classmate and girlfriend of Lynch, is cheerful and fond of new things. He is especially keen on learning and applying new technologies and is especially good at English.
After Microsoft released the version of Linq, Li Qiu has been focusing on the study and application of this technology, and has never been out of the dormitory every day except for the required courses. They have not been dating for nearly three months, the common communication is mainly through the network. One day, Lynch couldn't help it, so he went to qq...
LIN: Are you still studying Linq recently? Just a short time ago, the Chinese version of the documents have not been translated yet. Why are you so anxious?
Li: You don't know. It's too great to use Linq.
LIN: How great is it! But will he go to the dining room to cook for you?
Li: Let me know! A language-level integrated query (LAnguageINTegratedQUery), through which we can query various forms of data, such as SQL, Dataset, and XML.
LIN: It seems awesome! I don't believe it, so I don't have any disadvantages!
Li: Of course! No exception can be made to any vulnerability-prone Linq. For example, let's take it! Some people outside China have discovered that the Sum operator of one of the Linq statements may be faulty.
LIN: What's the problem?
Li: because it is mainly used for arithmetic and arithmetic operations and returns int32 values, it is easy to cause buffer overflow when computing a large amount of data.
LIN: Where do you know?
Lee: A Troy Magennis foreigner found, you're here to see http://aspiring-technology.com/blogs/troym/archive/2006/10/06/24.aspx
Ten minutes later ......
LIN: miserable! Why can't he understand the four methods that he reloads?
Li: I usually ask you to make C # grammar good! Version 3.5 is now available! Let's take a look!
Lin posted the first code:
Checked
{
Foreach (int v in source) sum + = v;
}
LIN: What does checked mean!
Li: It is used for overflow check. If overflow occurs, an exception is thrown.
Lin posted the second code:
Public static long? LongSum (this IEnumerable <int?> Source)
LIN: Why should I add one after long? Add this keyword before IEnumerable.
Li: Actually, long? Yes, it can be null, that is, the returned value can be null. This is a new feature of Linq, that is, the extension method.
Lin posted the third code:
Public static long LongSum <T> (this IEnumerable <T> source, Func <T, int> selector)
LIN: What does LongSum <T> mean?
Li: generic! You must have skipped the class last time. The teacher made it very clear in the class. It is actually a generic method, but the C # compiler will identify the type of this method after calling the parameter type of this method, so you do not need to assign the generic class to this method. The generic method is called like a common method.
LIN: Why is this function parameter written?
Li: according to its signature, because the parameter contains the this keyword, it should be an extension function. The first parameter indicates that this parameter is applicable to all generic collection classes. Func <T, int> is actually a generic delegate, which defines a method that encapsulates a parameter and returns the type value specified by the int parameter.
At this time, Lin qicai suddenly realized that he gradually understood a very abstract concept generic mentioned in the teacher's class. In addition to classes, generics also have methods, sets, and delegation. He felt embarrassed, but he should have no face for accuracy, so he made up his mind to master the technology of Linq! Don't face your girlfriend!