More Group Sites
Education Books
School Rankings
Jobless Net
Better Home
Enviro++
更好教育论坛


Help | Subscribe/Unsubscribe | Rules | Other Group Sites: Better Education | Better Education Forum
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Share
Options
View
Go to last post Go to first unread
hong  
#1 Posted : Thursday, 24 June 2010 2:59:11 PM(UTC)
hong

Rank: Administration

Reputation:

Groups: AcademicCoachingSchool, admin, Administration, BookSeller, CatholicSchool, CoachingAdult, CoachingProfessional, CoachingSports, ExtraCurriculumCoaching, IndependentSchool, Moderator, MusicTeacher, PrivateSchool, PublicSchool, SelectiveSchool, tutor
Joined: 23/11/2008(UTC)
Posts: 519

It seems that there are no methods in List of .Net 2.0 to find out whether there are duplicated items in a list. However, it's easy to determine whether each item in the list is unique. See the following examples:
List of integers:
Code:
        public static bool IsEachItemUnique(List<int> list)
        {
            bool bUnique = true;
            foreach (int n in list) 
            {
                bUnique &= (list.IndexOf(n) == list.LastIndexOf(n));
                if (!bUnique)
                    break;
            }
            return bUnique;
        }


List of strings:
Code:
        public static bool IsEachItemUnique(List<string> list)
        {
            bool bUnique = true;
            foreach (string s in list)
            {
                bUnique &= (list.IndexOf(s) == list.LastIndexOf(s));
                if (!bUnique)
                    break;
            }
            return bUnique;
        }

Edited by user Saturday, 16 April 2016 5:07:17 PM(UTC)  | Reason: Not specified

Sponsor
vyarthrot  
#2 Posted : Saturday, 16 April 2016 3:38:47 PM(UTC)
vyarthrot

Rank: Newbie

Reputation:

Groups: Member
Joined: 9/03/2015(UTC)
Posts: 1

try this one...

List<String> duplicates = lst.GroupBy(x => x)
.Where(g => g.Count() > 1)
.Select(g => g.Key)
.ToList();

More about......C# List

Throt
Rss Feed  Atom Feed
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.