Remove Duplicates from arrary .net
int[] k = new int[] { 0, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5, 6, 7, 8, 8, 9, 9, 9 };
for (int i = 0; i < k.Length - 1; i++)
{
if ((k[i] != k[i + 1]))
{
Response.Write(k[i]);
}
if ((k[k.Length - 2] == k[k.Length - 1]) && (i == k.Length - 2))
{
Response.Write(k[i]);
}
if ((k[k.Length - 2] != k[k.Length - 1]) && (i == k.Length - 2))
{
Response.Write(k[i + 1]);
}
}
---------------------------------------------------------------
string[] sArray = {"a", "b", "b", "c", "c", "d", "e", "f", "f"};
var sList = new ArrayList();
for (int i = 0; i < sArray.Length; i++)
{
if (sList.Contains(sArray[i]) == false)
{
sList.Add(sArray[i]);
}
}
var sNew = sList.ToArray();
for (int i = 0; i < sNew.Length; i++)
{
Response.Write(sNew[i]);
}
int[] k = new int[] { 0, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5, 6, 7, 8, 8, 9, 9, 9 };
for (int i = 0; i < k.Length - 1; i++)
{
if ((k[i] != k[i + 1]))
{
Response.Write(k[i]);
}
if ((k[k.Length - 2] == k[k.Length - 1]) && (i == k.Length - 2))
{
Response.Write(k[i]);
}
if ((k[k.Length - 2] != k[k.Length - 1]) && (i == k.Length - 2))
{
Response.Write(k[i + 1]);
}
}
---------------------------------------------------------------
string[] sArray = {"a", "b", "b", "c", "c", "d", "e", "f", "f"};
var sList = new ArrayList();
for (int i = 0; i < sArray.Length; i++)
{
if (sList.Contains(sArray[i]) == false)
{
sList.Add(sArray[i]);
}
}
var sNew = sList.ToArray();
for (int i = 0; i < sNew.Length; i++)
{
Response.Write(sNew[i]);
}