TGViewer
DotNetZoom DotNetZoom @dotnetzoom · 2.82K subscribers
Post #1288 10.5K

Forwarded from Software Philosophy

امکانات LINQ در NET 6.

✅ ۱- امکان مشخص کردن مقدار پیش‌فرض در OrDefault*

var item1 = list1.FirstOrDefault(i => i == 4, -1);
// -1

var item2 = list2.SingleOrDefault(i => i == "Item2", "Not found");
// Not found

➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖

✅۲- متدهای جدید با مدل By*:

- MinBy
- MaxBy
- DistinctBy
- ExceptBy
- IntersectBy
- UnionBy


List<Product> products = new()
{
new() { Name = "Product1", Price = 100 },
new() { Name = "Product2", Price = 5 },
new() { Name = "Product3", Price = 50 },
};

Product theCheapestProduct = products.MinBy(x => x.Price);
Product theMostExpensiveProduct = products.MaxBy(x => x.Price);
Console.WriteLine(theCheapestProduct);
// Output: Product { Name = Product2, Price = 5 }
Console.WriteLine(theMostExpensiveProduct);
// Output: Product { Name = Product1, Price = 100 }
➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖

✅۳- متد کاربردی Chunk :

IEnumerable<int> numbers = Enumerable.Range(1, 505);
IEnumerable<int[]> chunks = numbers.Chunk(100);

foreach (int[] chunk in chunks)
{
Console.WriteLine($"{chunk.First()}...{chunk.Last()}");
}

// Output:
// 1...100
// 101...200
// 201...300
// 301...400
// 401...500
// 501...505
➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖

✅۴- تابع Zip

int[] numbers = { 1, 2, 3, 4, };
string[] months = { "Jan", "Feb", "Mar" };
string[] seasons = { "Winter", "Winter", "Spring" };

var test = numbers.Zip(months).Zip(seasons);

foreach ((int, string, string) zipped in numbers.Zip(months, seasons))
{
Console.WriteLine($"{zipped.Item1} {zipped.Item2} {zipped.Item3}");
}
➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖

✅۵- پشتیبانی از Index در تابع ElementAt :

IEnumerable<int> numbers = new int[] { 1, 2, 3, 4, 5 };
int last = numbers.ElementAt(^0);
Console.WriteLine(last); // 5
➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖

✅۶- پشتیبانی از Range در تابع Take :
var taken1 = numbers.Take(2..4);
➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖

✅۷- جلوگیری از شمارش تایپ‌های غیر Enumerable:

numbers.TryGetNonEnumeratedCount(out int count)

➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖

https://raygun.com/blog/linq-net-6-improvements/

⁉️ برای بحث و تبادل نظر فنی در مورد این پست، برروی دکمه «نظرت را بگو» کلیک کنید.

#حامد_حاجیلو (لینکدین)

کانال تلگرام:
@SoftwarePhilosophy

________
Raygun Blog A look at the upcoming improvements to LINQ in .NET 6 The upcoming release of .NET 6 brings a number of really interesting features, including a suite of new LINQ capabilities.
More from @dotnetzoom
  1. Dec 6, 2021انتقال داده ها به واسطه Azure Service Bus امروزه سرعت انتقال داده‌ها از اهمیت بالایی برخور…
  2. Nov 29, 2021اضافه شدن قابلیت Temporal Table به EF Core 6 ➖ مایکروسافت در سال 2016 قابلیت Temporal Tabl…
  3. Nov 10, 2021همه چیز در مورد NET Core 6. دیروز نسخه رسمی NET Core 6. به همراه نسخه رسمی Visual Studio 2…
  4. Nov 10, 2021نسخه نهایی NET 6.0 منتشر شد. نسخه 6.0 دات نت به صورت طولانی مدت پشتیبانی میشود (LTS) و توس…
  5. Nov 8, 2021کنفرانس NET. Conf هر سال خبرهای هیجان‌انگیزی داره. امسال هم NET. خبر های خوب و جذابی داره…
  6. Oct 20, 2021شروع به کار با Web API در ASP NET Core 6.0 https://youtu.be/hONSDm4gs_I
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →