[C#][System.Linq] Some convenient data processing methods (Range, Select)
[C#][System.Linq] Some convenient data processing methods (Range, Select) Because I am used to some convenient methods in Python, I immediately checked whether there are similar methods in C#. 1. Range() method In Python, range (Start, End, Step) can directly generate an iterable object, which can be used to process certain code blocks that need to be looped multiple times: (Note: End in the Range method is an open interval, and the actual value of range (1, 10) is (1 ~ 9)) 1 for item in range(1, 10 ): 2 print span>(item, end=”) 3 # span> Output: 4 # 123456789 The same method can be used in C#: Enumerable.Range(Start, Count) in the System.Linq namespace 1 foreach(int item in Enumerable.Range(1, 10 )) 2 Console.Write($”{item}=”); 3 // Output: 4 // 1=2=3=4=5=6=7=8=9=10= The parameters in range (Start, End, Step) and Enumerable.Range (Start, Count) have different meanings: range is start, end, step, and the generated object does not include the End element. Range: The sequence is start, quantity, that is, starting from 1 and counting backwards 10 numbers, so the result of the above output is 1~10. If it is changed to Range(0, 10), the result will be 0~9. 2. Select() method It corresponds to…