How to remove duplicate from array [Resolved]

Posted by Jitenkumar under Visual Studio on 6/30/2013 | Points: 10 | Views : 3630 | Status : [Member] | Replies : 2
Suppose an array contains repeated names then how to remove the duplicate names in an array.




Responses

Posted by: Satyapriyanayak on: 6/30/2013 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Rdup
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Original Names");

string[] strs = new string[4] { "a", "b", "c", "a" };

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();


}
}
}


If this post helps you mark it as answer
Thanks

Jitenkumar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Venkat0454 on: 7/13/2013 [Member] Starter | Points: 25

Up
0
Down
using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;

namespace Linq
{
class Program
{
static void Main(string[] args)
{
var strs = new string[4] { "a", "b", "c", "a" };

var Dis = strs.Distinct().ToArray();
Console.WriteLine("Distinct Names");
foreach (var a in Dis)
{
Console.WriteLine(a);

}
Console.ReadLine();
}
}
}

Var Dis will Contain Distinct values

Jitenkumar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response