Click here to Skip to main content
15,922,419 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a list in which it contain ID,Bankmisid
so the data list contain is like


Bankmisid | ID
1 | 45
2 | 45
3 | 45
4 | 46



so i need to find duplicate and throw exception
Posted
Updated 21-Jan-16 0:06am
v2

1 solution

Try:
C#
if (myList.GroupBy(i => i.ID).Where(g => g.Count > 1).Select(g => g.Key).Count() > 0)
   {
   throw ...

[edit]Oops![/edit]
 
Share this answer
 
v2
Comments
Aviinash 21-Jan-16 6:10am    
It is showing error g does not exist in current context
F-ES Sitecore 21-Jan-16 6:20am    
if (myList.GroupBy(i => i.ID).Where(g => g.Count() > 1).Select(g => g.Key).Count() > 0)
OriginalGriff 21-Jan-16 6:20am    
I forgot the lambda prefix!
Fixed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900