ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Compare two List collection using C# in ASP.Net<p>Hi bebins,</p> <p>Refer the below sample.</p> <p><span style="text-decoration: underline;">C#</span></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { &nbsp;&nbsp;&nbsp; var list1 = new List&lt;PriceExcel&gt;(); &nbsp;&nbsp;&nbsp; var list2 = new List&lt;PriceExcel&gt;(); &nbsp;&nbsp;&nbsp; list1.Add(new PriceExcel { Name = &#34;Test1&#34;, Date = &#34;90&#34;, Age = &#34;20&#34; }); &nbsp;&nbsp;&nbsp; list2.Add(new PriceExcel { Name = &#34;Test1&#34;, Date = &#34;70&#34;, Age = &#34;20&#34; }); &nbsp;&nbsp;&nbsp; bool isSame = false; &nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; list1.Count; i++) &nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string name1 = list1[i].Name; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string date1 = list1[i].Date; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string age1 = list1[i].Age; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int j = 0; j &lt; list2.Count; j++) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string name2 = list2[j].Name; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string date2 = list2[j].Date; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string age2 = list2[j].Age; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (name1.Equals(name2) &amp;&amp; date1.Equals(date2) &amp;&amp; age1.Equals(age2)) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; isSame = true; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; isSame = false; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; if (isSame) &nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ClientScript.RegisterClientScriptBlock(this.GetType(), &#34;&#34;, &#34;alert(&#39;Data with same value exist&#39;)&#34;, true); &nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; else &nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ClientScript.RegisterClientScriptBlock(this.GetType(), &#34;&#34;, &#34;alert(&#39;Data with same value not exist&#39;)&#34;, true); &nbsp;&nbsp;&nbsp; } } class PriceExcel { &nbsp;&nbsp;&nbsp; public string Name { get; set; } &nbsp;&nbsp;&nbsp; public string Date { get; set; } &nbsp;&nbsp;&nbsp; public string Age { get; set; } }</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/207204/Compare-two-List-collection-using-C-in-ASPNet/https://www.aspforums.net:443/Threads/207204/Compare-two-List-collection-using-C-in-ASPNet/Wed, 31 May 2017 07:12:56 GMT