<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Shayan</title>
    <description>The latest articles on DEV Community by Shayan (@shayankamalzadeh).</description>
    <link>https://dev.to/shayankamalzadeh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F602125%2F1ef97d67-a593-440e-a3dd-3bbc3dee77ac.jpeg</url>
      <title>DEV Community: Shayan</title>
      <link>https://dev.to/shayankamalzadeh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shayankamalzadeh"/>
    <language>en</language>
    <item>
      <title>Equality Array(Data Structure tips in C#)</title>
      <dc:creator>Shayan</dc:creator>
      <pubDate>Wed, 20 Apr 2022 02:33:33 +0000</pubDate>
      <link>https://dev.to/shayankamalzadeh/equality-arraydata-structure-tips-in-c-5dpi</link>
      <guid>https://dev.to/shayankamalzadeh/equality-arraydata-structure-tips-in-c-5dpi</guid>
      <description>&lt;p&gt;Hello guys, today I want to focus on Array, actually, I hope you know about array and in this article, I try to a bit deeper into it. so let's go…&lt;br&gt;
I start with a sample:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--F0NPMjAq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i585t5u6f10d884y4szg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--F0NPMjAq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i585t5u6f10d884y4szg.jpeg" alt="Image description" width="278" height="347"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;define 2 DateTime array&lt;br&gt;
I have defined exactly 2 DateTime arrays like each other, just the names are different.&lt;br&gt;
What do you think? are they equal to each other?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--f-xhlaFk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vp7yir6fm79tn62rtk6e.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--f-xhlaFk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vp7yir6fm79tn62rtk6e.jpeg" alt="Image description" width="365" height="78"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you see, when using the ‘==’ operator for 2 arrays, however, each item is exactly like the other, the result is false!&lt;br&gt;
I hope you remember Value-type and Reference-type.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fEfHSOtt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o2xxfgiesuf0qij8av00.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fEfHSOtt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o2xxfgiesuf0qij8av00.png" alt="Image description" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When I define a value-Type like DateTime, each variable is put in memory like the above picture so “mydate!=yourdate”.Now let’s look at how Reference-Types are stored&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6EHb32ed--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2amn8l30uesak3rbfzpd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6EHb32ed--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2amn8l30uesak3rbfzpd.png" alt="Image description" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Reference-Type means the variable doesn't actually contain the string ”Shayan” and stores the address of memory where store the variable(xx).&lt;br&gt;
However DataTime is Value-Type,DataType[] is Referencetype because ,Array is Reference-Type&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IL5aGST2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/59ic2wy6czl9o4pwc7mb.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IL5aGST2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/59ic2wy6czl9o4pwc7mb.jpeg" alt="Image description" width="880" height="493"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Therefore when defining 2 Arrays with the same values, they are located at different addresses, and bankHols1==bankHols2 is false &lt;strong&gt;(why???)&lt;/strong&gt;&lt;br&gt;
Because the “==” operator for ReferenceType check Addresses and addresses are different.&lt;br&gt;
this rule is ok for all Reference-Type collections in c#, But be careful about “String”.&lt;br&gt;
The string is reference type but Microsoft overrides the”==” operator for it so when using the “==” operator for 2 string that is the same as each other the result is true.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QI35qkZB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wl6g6dckttoracgegz7v.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QI35qkZB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wl6g6dckttoracgegz7v.jpeg" alt="Image description" width="482" height="183"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now the question is: &lt;strong&gt;how can compare just the value of 2 arrays?&lt;/strong&gt;&lt;br&gt;
Microsoft introduces the &lt;strong&gt;SequenceEqual()&lt;/strong&gt; extension method (in the LinQ)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--71Q82Yhe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cws28qfbt7qdoo0um285.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--71Q82Yhe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cws28qfbt7qdoo0um285.jpeg" alt="Image description" width="538" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But be careful when using SequenceEqual(), it is too expensive because comparing each pair of elements if it is a bit large could be a lot of operations.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Threadpool, Thread</title>
      <dc:creator>Shayan</dc:creator>
      <pubDate>Tue, 23 Mar 2021 20:49:05 +0000</pubDate>
      <link>https://dev.to/shayankamalzadeh/threadpool-thread-mj8</link>
      <guid>https://dev.to/shayankamalzadeh/threadpool-thread-mj8</guid>
      <description>&lt;p&gt;Hello hello&lt;br&gt;
Today I want to talk about Thread Threadpool and the type of Threads in .Net.&lt;br&gt;
&lt;strong&gt;What is a thread pool?&lt;/strong&gt;&lt;br&gt;
Before talking about Threadpool, I have a question, Do you know about Thread??&lt;br&gt;
So first let me talk about Thread.&lt;br&gt;
A thread controls the flow of an executable program. By default, a program has one thread called Main&lt;br&gt;
Thread. Main Thread starts when control enters in the Main method and it terminates when the Main method returns.&lt;br&gt;
If the execution of a program is controlled by more than one thread, it’s called a Multithreaded&lt;/p&gt;

&lt;p&gt;Application. Such a program increases the performance and response time of an application.&lt;br&gt;
A thread can be created by using System.Threading.Thread class. A thread can only be manipulated on a method. For example, MainThread needs the Main method to control the flow of a program.&lt;br&gt;
Thread Pool&lt;br&gt;
The cost of instantiating a managed thread is higher than reusing a free thread. In .NET, a thread pool is helpful to reuse the free threads. A thread pool is a collection of background threads created by a system and are available to perform any task when required.&lt;br&gt;
When a program requires an extra thread, it is more efficient to use available free threads from a thread pool because it can save the cost of creating a thread. And when a thread completes its execution, it can go back to the thread pool so other programs can reuse the same thread again.&lt;br&gt;
&lt;strong&gt;Limitation of Thread Pool&lt;/strong&gt;&lt;br&gt;
• It is hard to tell when a thread of a thread pool has finished its execution.&lt;br&gt;
• There is no “Start” method, so we cannot tell when a thread of a thread pool has started its execution because it is being managed by the system.&lt;br&gt;
• It can’t manage a thread that returns a value.&lt;/p&gt;

&lt;p&gt;As you see, I talked about the background thread.&lt;/p&gt;

&lt;p&gt;We have two types of Thread, &lt;strong&gt;Background and Foreground Thread&lt;/strong&gt;&lt;br&gt;
There are two kinds of threads in C#, i.e., Foreground thread and Background thread. By default, in C# all threads are initialized as foreground thread. An application cannot terminate its execution until all its foreground threads are completed.&lt;br&gt;
A background thread is almost identical to a foreground thread. The one difference is that, if the Main Thread has completed its execution and the background thread is the only thread remaining in the application, the Main Thread will terminate the application and not wait for the background thread to be completed.&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>threadpool</category>
      <category>thread</category>
      <category>dotnet</category>
    </item>
  </channel>
</rss>
