Docker在官網下載Tomcat映象裡面沒有ip addr等命令解決思路
NET 6 中新增的LINQ 方法
微軟太給力了NET5 LINQ很多功能點還沒用到NET6 LINQ 新功能就到來了 而且 NET6 有些功能確實很貼切列如:
Chunk
TryGetNonEnumeratedCount
Zip
ElementAt
MaxBy
MinBy
DistinctBy
ExceptBy
IntersectBy
UnionBy
FirstOrDefault
LastOrDefault
SingleOrDefault
Take
Chunk 該方法將序列的元素拆分為指定大小的區塊
st<string> names = new List<string>() {"鳳年", "陸丞燕", "呵呵", "姜泥", "南宮僕射", "王初冬", "紅薯", "裴南葦" };
var newNames=names.Chunk(3);
foreach (var name in newNames)
{
Console.WriteLine(String.Join(",",name));
}
Console.ReadKey();
TryGetNonEnumeratedCount 該方法嘗試在不強制列舉的情況下獲取可列舉的源的計數
List<string> names = new List<string>() {"鳳年", "陸丞燕", "呵呵", "姜泥", "南宮僕射", "王初冬", "紅薯", "裴南葦" };
int num = 0;
names.TryGetNonEnumeratedCount(out num);
Console.WriteLine(num);
Console.ReadKey();
Zip該方法將兩個陣列進行整合成為一個 ValueTuple<T,SecondT>陣列
List<string> names1 = new List<string>() { "鳳年", "陸丞燕", "姜泥", "南宮僕射" };
List<string> names2 = new List<string>() { "紅薯","王初冬", "呵呵", "裴南葦" };
var names=names1.Zip(names2);
Console.WriteLine(String.Join(",", names));
Console.ReadKey();
ElementAt 該方法返回元素指定索引或者結束的索引
List<string> names = new List<string>() {"鳳年", "陸丞燕", "呵呵", "姜泥", "南宮僕射", "王初冬", "紅薯", "裴南葦" };
var index1=names.ElementAt(3);
var index2=names.ElementAt(^3);
Console.WriteLine(index1);
Console.WriteLine(index2);
Console.ReadKey();
MaxBy 該方法放回陣列或是列表中的最大值
List<int> numbers = new List<int>() { 100,99,5, 4, 1, 3, 9, 8, 6, 7, 12, 10 };
var maxnum= numbers.MaxBy(x => x);
Console.WriteLine(result);
Console.ReadKey();
MinBy該方法放回陣列或是列表中的最小值
List<int> numbers = new List<int>() { 100, 99, 5, 4, 1, 3, 9, 8, 6, 7, 12, 10 };
var result = numbers.MinBy(x => x);
Console.WriteLine(result);
Console.ReadKey();
DistinctBy該方法根據某元素去重(可以自定義元素屬性去重)
List<string> names = new List<string>() { "鳳年", "陸丞燕", "呵呵", "姜泥", "南宮僕射", "王初冬", "紅薯", "裴南葦", "鳳年", "陸丞燕", "呵呵", "姜泥", "南宮僕射", "王初冬", "紅薯", "裴南葦" };
var result = names.DistinctBy(x => x);
Console.WriteLine(String.Join(",",result));
Console.ReadKey();
ExceptBy該方法返回 兩個序列的元素的集合差值的序列
List<string> names1 = new List<string>() { "鳳年", "陸丞燕", "呵呵", "姜泥", "紅薯" };
List<string> names2 = new List<string>() { "鳳年", "陸丞燕", "姜泥", "南宮僕射", "王初冬", "紅薯", "裴南葦" };
List<string> names3 = new List<string>();
var names = names2.ExceptBy(names1, names1 => names1);
Console.WriteLine(names);
IntersectBy 該方法返回兩個序列元素 得交集
List<string> names1 = new List<string>() { "鳳年", "陸丞燕", "呵呵", "姜泥", "紅薯" };
List<string> names2 = new List<string>() { "鳳年", "陸丞燕", "姜泥", "南宮僕射", "王初冬", "紅薯", "裴南葦" };
List<string> names3 = new List<string>();
var names = names2.IntersectBy(names1, names1 => names1);
Console.WriteLine(String.Join(" ", names));
UnionBy該方法連線不同集合,過濾某元素相同項
List<string> names1 = new List<string>() { "鳳年", "陸丞燕", "呵呵", "姜泥", "紅薯" };
List<string> names2 = new List<string>() { "鳳年", "陸丞燕", "姜泥", "南宮僕射", "王初冬", "紅薯", "裴南葦" };
List<string> names3 = new List<string>();
var names = names2.UnionBy(names1, names1 => names1);
Console.WriteLine(String.Join(" ", names));
FirstOrDefault該方法返回序列中滿足條件的第一個元素;如果未找到這樣的元素,則返回預設值
List<string> names = new List<string>() { "鳳年", "陸丞燕", "呵呵", "姜泥", "南宮僕射", "王初冬", "紅薯", "裴南葦" };
var result=names.FirstOrDefault(x=>x.Contains("人屠"),"鳳年");
Console.WriteLine(result);
LastOrDefault該方法返回序列中的最後一個元素;如果未找到該元素,則返回預設值
List<string> names = new List<string>() { "鳳年", "陸丞燕", "呵呵", "姜泥", "南宮僕射", "王初冬", "紅薯", "裴南葦" };
var result = names.LastOrDefault(x => x.Contains("人屠"), "呵呵");
Console.WriteLine(result);
SingleOrDefault 該方法返回序列中的唯一元素;如果該序列為空,則返回預設值;如果該序列包含多個元素,此方法將引發異常。
string[] strName = { "鳳年" };
string[] strNameEmpty = { };
string[] strEmpty = { "鳳年", "姜泥" };
try
{
string tempName = strName.SingleOrDefault();
Console.WriteLine("SingleOrDefault()第一種 返回序列中的唯一記錄。");
Console.WriteLine("資訊為:{0}", tempName);
string tempNameEmpty = strNameEmpty.SingleOrDefault();
Console.WriteLine("SingleOrDefault()第二種 如果該序列為空,則返回預設值。");
Console.WriteLine("資訊為:{0}", tempNameEmpty);
string tempEmpty = strEmpty.SingleOrDefault();
}
catch (Exception ex)
{
Console.WriteLine("SingleOrDefault()第三種 如果該序列包含多個元素,則引發異常。");
Console.WriteLine("資訊為:{0}", ex.Message);
}
Take 該方法 從序列的開頭返回指定數量的相鄰元素
List<string> names = new List<string>() { "鳳年", "陸丞燕", "呵呵", "姜泥", "南宮僕射", "王初冬", "紅薯", "裴南葦" };
var result = names.Take(3);
Console.WriteLine(String.Join(",",result.ToList()));
Console.ReadKey();
#總結 以上就是NET6 更新的常用方法