Duplicate elements
How can I remove duplicate elements from an array?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Feb 14, 2012, 3:07 AM
Another way of doing it,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Remove_duplicate
{
class Program
{
static void Main(string[] args)
{
String[] myString = new String[] { "Raj", "Raj", "Ravi", "Ravi" ,"Rahul"};
IEnumerable
foreach (String theString in disctinctName)
{
Console.WriteLine(theString);
}
Console.ReadLine();
}
}
}
Thanks
Satyapriya NayakPosted Feb 14, 2012, 3:02 AM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Remove_duplicate
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Original Names");
string[] strs = new string[4] { "Raj", "Ravi", "Ravi", "Rahul" };
for (int i = 0; i < strs.Length; i++)
{
Console.WriteLine(strs[i]);
}
Console.WriteLine("Distinct Names");
var Results = strs.Distinct();
foreach (var item in Results)
{
Console.WriteLine(item);
}
Console.ReadLine();
}
}
}
Thanks