Friday 6 June 2014

string array Distinct C#

string strData = "Role,Rolename,Rolepwd,Rolename,Rolepwd,lll";
string[] sArray = strData.Split(',');
HashSet set = new HashSet(sArray);
string[] result = new string[set.Count];
set.CopyTo(result);
DisplaySet(set);
---------------------------
private void DisplaySet(HashSet set)
{
foreach (string i in set)
{
Response.Write(i);
}
}
-------------------
string strArray = "a3,r8,t4,a3,y7,a3";
string[] arr = strArray.Split(',');
arr = arr.Distinct().ToArray();
--------------------------------------------
int[] s = { 1, 2, 3, 3, 4};
int[] q = s.Distinct().ToArray();
-----------------------------------