Finding Duplicate values in String:
First Method:
string[] s1 ={ "a","a","a"};
List<string> myList1 = new List<string>();
List<string> duplicates = new List<string>();
foreach (String s in s1)
{
if (!myList1.Contains(s))
{
myList1.Add(s);
}
else {
duplicates.Add(s);
}
// show list without duplicates...
foreach (String s in myList1)
{
Console.WriteLine(s);
}
// show duplicates list...
foreach (String s in duplicates)
{
Console.WriteLine(s);
}
----------------------------------------------
Second Method:
int[] p = { 1, 2, 9, 9, 6};
int[] q = p.Distinct().ToArray();
No comments:
Post a Comment