Finding Duplicate string values in a String
Method1:
string[] ss ={ "1","1","1"};
List<string> myList = new List<string>();
List<string> duplicates = new List<string>();
foreach (String s in ss) {
if (!myList.Contains(s)) {
myList.Add(s);
} else {
duplicates.Add(s);
}
// show list without duplicates
foreach (String s in myList) {
Console.WriteLine(s);
}
// show duplicates list
foreach (String s in duplicates) {
Console.WriteLine(s);
}
----------------------------------------------
method2:
int[] s = { 1, 2, 3, 3, 4};
int[] q = s.Distinct().ToArray();
No comments:
Post a Comment