<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>بایگانی‌های .Net6 - بازسازی</title>
	<atom:link href="http://recompile.ir/tag/net6/feed/" rel="self" type="application/rss+xml" />
	<link>https://recompile.ir/tag/net6/</link>
	<description>مشاوره و آموزش برای بازسازی و تغییر</description>
	<lastBuildDate>Sat, 10 Jul 2021 09:46:51 +0000</lastBuildDate>
	<language>fa-IR</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>http://recompile.ir/wp-content/uploads/2020/08/cropped-android-chrome-512x512-1-32x32.png</url>
	<title>بایگانی‌های .Net6 - بازسازی</title>
	<link>https://recompile.ir/tag/net6/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Top 10 New .NET 6.0 API</title>
		<link>http://recompile.ir/learning/top-10-new-net-6-0-api/</link>
					<comments>http://recompile.ir/learning/top-10-new-net-6-0-api/#respond</comments>
		
		<dc:creator><![CDATA[محمد خوش کشت]]></dc:creator>
		<pubDate>Sat, 10 Jul 2021 09:42:58 +0000</pubDate>
				<category><![CDATA[آموزش]]></category>
		<category><![CDATA[وبلاگ و اخبار]]></category>
		<category><![CDATA[.Net6]]></category>
		<category><![CDATA[API]]></category>
		<guid isPermaLink="false">http://recompile.ir/?p=362</guid>

					<description><![CDATA[<p>.NET 6 API های جدید را برای توسعه ساده تر و سریعتر معرفی کرده که به توضیح آنها میپردازیم: 1- تا به حال دو کلاس DateTime , TimeSpan برای هندل کردن عملیات تاریخ وجود داشت اما د ر.NET 6 دو تابع DateOnly , TimeOnly برای کار راحت تر با تاریخ و زمان اضافه شده است [&#8230;]</p>
<p>نوشته <a href="http://recompile.ir/learning/top-10-new-net-6-0-api/">Top 10 New .NET 6.0 API</a> اولین بار در <a href="http://recompile.ir">بازسازی</a>. پدیدار شد.</p>
]]></description>
										<content:encoded><![CDATA[<span class="span-reading-time rt-reading-time" style="display: block;"><span class="rt-label rt-prefix">زمان مطالعه: </span> <span class="rt-time"> 3</span> <span class="rt-label rt-postfix">دقیقه</span></span>
<p>.NET 6 API های جدید را برای توسعه ساده تر و سریعتر معرفی کرده که به توضیح آنها میپردازیم:</p>



<p>1- تا به حال دو کلاس DateTime , TimeSpan برای هندل کردن عملیات تاریخ وجود داشت اما د ر.NET 6 دو تابع DateOnly , TimeOnly برای کار راحت تر با تاریخ و زمان اضافه شده است</p>



<p></p>



<pre class="wp-block-code"><code>var dateOnly = new DateOnly(2021,7,7);
Assert.IsTrue(dateOnly.ToString() == "07-Jul-21");
Assert.IsTrue(dateOnly.AddMonths(1).ToString() == "07-Aug-21");
 
var timeOnly = new TimeOnly(11, 43, 57);
Assert.IsTrue(timeOnly.ToString() == "11:43 AM");
Assert.IsTrue(timeOnly.AddHours(1) > timeOnly);
Assert.IsTrue(timeOnly.AddHours(1) - timeOnly == new TimeSpan(1,0,0));
 
DateTime dateTime = dateOnly.ToDateTime(timeOnly);
Assert.IsTrue(dateTime.ToString() == "07-Jul-21 11:43:57 AM");
Assert.IsTrue(DateOnly.FromDateTime(dateTime) == dateOnly);
Assert.IsTrue(TimeOnly.FromDateTime(dateTime) == timeOnly);</code></pre>



<p><br>2- برای پرفورمنس بالاتر صف اولویت دار PriorityQueue اضافه شده است که در آن اولویت آیتمها قبل تغییر نیست (سریعتر پیمایش می شود) و پیاده سازی آن هم الزاما پایدار نمی باشد. صف اولویت دار زمانی پایدار است که آیتمها به همان ترتیب برداشته شدن وارد صف شوند</p>



<p></p>



<pre class="wp-block-code"><code>var youngerFirstQueue = new PriorityQueue&lt;string, int>();
youngerFirstQueue.Enqueue("Lena", 7);
youngerFirstQueue.Enqueue("Patrick", 46);
youngerFirstQueue.Enqueue("Paul", 7);
Assert.IsTrue(youngerFirstQueue.Dequeue() == "Lena");
Assert.IsTrue(youngerFirstQueue.Dequeue() == "Paul");
Assert.IsTrue(youngerFirstQueue.Dequeue() == "Patrick");</code></pre>



<p><br>3- Index و Range در LINQ قابل استفاده شده اند.Index , Range از قابلیتهای C#8 هستند. توضیح<br></p>



<pre class="wp-block-code"><code>// 6 element indexed from 0 to 5
var arr = new &#91;] {0, 1, 2, 3, 4, 5};
Assert.IsTrue(arr.ElementAt(^2) == 4); // Take the second element from the end
Assert.IsTrue(arr.ElementAtOrDefault(^10) == default); // No such index
Assert.IsTrue(arr.Take(2..4).SequenceEqual(new&#91;] { 2, 3 }));
Assert.IsTrue(arr.Take(2..^2).SequenceEqual(new&#91;] { 2, 3 }));
 
// New Index Range usage with their pre .NET 6 equivalent
Assert.IsTrue(arr.Take(..2).SequenceEqual(new&#91;] { 0, 1 }));
Assert.IsTrue(arr.Take(2).SequenceEqual(new&#91;] { 0, 1 }));
 
Assert.IsTrue(arr.Take(2..).SequenceEqual(new&#91;] { 2, 3, 4, 5 }));
Assert.IsTrue(arr.Skip(2).SequenceEqual(new&#91;] { 2, 3, 4, 5 }));
 
Assert.IsTrue(arr.Take(^2..).SequenceEqual(new&#91;] { 4, 5 }));
Assert.IsTrue(arr.TakeLast(2).SequenceEqual(new&#91;] { 4, 5 }));
 
Assert.IsTrue(arr.Take(..^2).SequenceEqual(new&#91;] { 0, 1, 2, 3 }));
Assert.IsTrue(arr.SkipLast(2).SequenceEqual(new&#91;] { 0, 1, 2, 3 }));</code></pre>



<p>4- برای FirstOrDefault(), LastOrDefault() SingleOrDefault() میتوانید مقدار پیش فرض تعیین کنید<br></p>



<pre class="wp-block-code"><code>
var arr = new &#91;] {0, 1, 2, 3, 4, 5};
Assert.IsTrue(arr.FirstOrDefault(x => x > 6) == 0);
Assert.IsTrue(arr.FirstOrDefault(x => x > 6, -1) == -1);</code></pre>



<p>5- قابلیتهای MaxBy(), MinBy(), DistinctBy(), UnionBy(), IntersectBy(), ExceptBy() اضافه شد اند<br></p>



<pre class="wp-block-code"><code>var buckets1 = new&#91;] {
   (Color: "Red", Price: 7), 
   (Color: "Blue", Price: 10), 
   (Color: "Green", Price: 7),
};
var buckets2 = new&#91;] {
   (Color: "White", Price: 7), 
   (Color: "Black", Price: 12),
};
Assert.IsTrue(buckets1.MaxBy(p => p.Price).Color == "Blue"); 
Assert.IsTrue(buckets1.MinBy(p => p.Price).Color == "Red");
 
// bucket from buckets1 distinct by price
Assert.IsTrue(buckets1.DistinctBy(p => p.Price)    
   .Select(p => p.Color).SequenceEqual(new &#91;] {"Red", "Blue" }));
 
// Union from buckets1 and buckets2 distinct by price
Assert.IsTrue(buckets1.UnionBy(buckets2, p => p.Price)    
   .Select(p => p.Color).SequenceEqual(new&#91;] { "Red", "Blue", "Black" }));
 
// Unique bucket from buckets1 with a price in buckets2
Assert.IsTrue(buckets1.IntersectBy(buckets2.Select(p => p.Price), p => p.Price)    
   .Select(p => p.Color).SequenceEqual(new&#91;] { "Red" }));
 
// Unique bucket from buckets1 with a price Not in buckets2
Assert.IsTrue(buckets1.ExceptBy(buckets2.Select(p => p.Price), p => p.Price)    
   .Select(p => p.Color).SequenceEqual(new&#91;] { "Blue"}));</code></pre>



<p>6- چون ممکن است پیدا کردن تعداد پروفورمنس را تحت تاثیر بگذارد تابع TryGetNonEnumeratedCount برای تست کردن گرفتن تعداد طراحی شده که true, false می دهد<br></p>



<pre class="wp-block-code"><code>class MyCollection&lt;T> : IEnumerable&lt;T> {
   public IEnumerator&lt;T> GetEnumerator() { throw new NotImplementedException(); }
   IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
}
 
...
 
IEnumerable&lt;int> seq1 = new&#91;] { 0, 1, 2, 3, 4, 5 };
Assert.IsTrue(seq1.TryGetNonEnumeratedCount(out int count1));
Assert.IsTrue(count1 == 6);
 
IEnumerable&lt;int> seq2 = new MyCollection&lt;int>();
Assert.IsFalse(seq2.TryGetNonEnumeratedCount(out int count2));</code></pre>



<p>7- اضافه شدن IEnumerable Chunk و IQueryable Chunk و برای راحت تر کردن عملیات chunk کردن و خواندن توالی<br></p>



<pre class="wp-block-code"><code>var arr = new&#91;] { 0, 1, 2, 3, 4, 5, 6 };
IEnumerable&lt;int&#91;]> chuncks = arr.Chunk(3);
Assert.IsTrue(chuncks.ElementAt(0).SequenceEqual(new&#91;] { 0, 1, 2 }));
Assert.IsTrue(chuncks.ElementAt(1).SequenceEqual(new&#91;] { 3, 4, 5 }));
Assert.IsTrue(chuncks.ElementAt(2).SequenceEqual(new&#91;] { 6 }));</code></pre>



<p>8- تا به حال می شد تا 2 توالی را Zip کنیم اما حالا امکان Zip کردن سه توالی اضافه شده است.<br></p>



<pre class="wp-block-code"><code>var integers = Enumerable.Range(0, 4);
var squares = integers.Select(i => i * i);
var cubes = integers.Select(i => i * i * i);
var zip = integers.Zip(squares, cubes).ToArray();
foreach ((int i, int square, int cube) in zip) {
   Assert.IsTrue($"{i} {square} {cube}" == $"{i} {i * i} {i * i * i}");
}</code></pre>



<p>9- اضافه شدن EnsureCapacity() به List, Stack, Queue . باتوجه به اینکه همه این کالکشن ها یک ظرفیت داخلی دارند و با اضافه شدن به لیست آنها ظرفیت افزایش پیدا می کند و این کار می تواند در پرفورمنس موثر باشد، شما می توانید ظرفیت لازم را برای هر کدام تعیین کنید.<br></p>



<pre class="wp-block-code"><code>var list = new List&lt;int> {1, 2};
Assert.IsTrue(list.Capacity &lt; 100);
list.EnsureCapacity(100);
Assert.IsTrue(list.Count == 2);
Assert.IsTrue(list.Capacity == 100);
list.EnsureCapacity(50);
Assert.IsTrue(list.Capacity == 100);
for(int i = list.Count; i &lt; 100; i++) {
   list.Add(i);
}
Assert.IsTrue(list.Count == 100);
Assert.IsTrue(list.Capacity == 100);</code></pre>



<p>10- اضافه شدن متد جدید Task.WaitAsync() .اگر timeout رخ بدهد هم تسک و هم wait کنسل می شوند</p>



<pre class="wp-block-code"><code>
public Task Task.WaitAsync(CancellationToken cancellationToken);
public Task Task.WaitAsync(TimeSpan timeout);
public Task Task.WaitAsync(TimeSpan timeout, CancellationToken cancellationToken)</code></pre>



<p>منبع : https://blog.ndepend.com/top-10-new-net-6-0-api/</p>



<p></p>
<p>بازدیدها: 1</p><p>نوشته <a href="http://recompile.ir/learning/top-10-new-net-6-0-api/">Top 10 New .NET 6.0 API</a> اولین بار در <a href="http://recompile.ir">بازسازی</a>. پدیدار شد.</p>
]]></content:encoded>
					
					<wfw:commentRss>http://recompile.ir/learning/top-10-new-net-6-0-api/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
