1 // [3]*10 2 Enumerable.Range(0,10).ToArray(); 3 4 // [X*2 for x in range(5) if x%3==0] 5 Enumerable.Range(0, 5).Select(x=>x*2).ToArray(); 6 7 // mat =[[0]*5 for _ in range(5)] 8 var mat = Enumerable.Range(0, 5).Select(_=> Enumerable.Repeat(0, 5).ToArray()).ToArray(); 9 var mat2 = new int[5,5]; 10 11 var s_ = new string ('-', 20); 12 13 var arr = Enumerable.Range(0, 20).ToArray(); 14 var t = arr[..^10]; 15 16 var t2 = "hello, world"[2..8]; 17 18 var t3 = arr.Skip(2).SkipLast(5); 19 20 var s = "hello"; 21 foreach (var (i,c) in Enumerable(s, 1)){ 22 Console.WriteLine(i, c); 23 } 24 25 IEnumerable<(int , T)> Enumerable<T>(IEnumerable<T> items, int start=0){ 26 int i = start; 27 foreach(var it in items){ 28 yield return (i++, it); 29 } 30 } 31 32 var a = new int []{1, 2,3,4,5}; 33 foreach(var p in s.Zip(a)){ 34 Console.WriteLine(p); 35 } 36 37 foreach(var (i, c) in Enumerable.Range(1, s.Length).Zip(s)){ 38 Console.WriteLine(i, c); 39 } 40 41 // 免费字体 42 //www.nerdfonts.com
标签:ToArray,python,写法,int,Range,foreach,var,net,Enumerable From: https://www.cnblogs.com/egreen/p/16990556.html