Quote:
not using c# in built function
Why not? You can simply use the
Distinct
method instead of writing a method yourself:
string[] newstr = str.Distinct().ToArray();
It's really not necessary to write a method yourself.
[Edit]
If you really want a function that's not built-in, create this extension method:
public static class ExtensionMethods
{
public static IEnumerable<T> DistinctNonBuiltIn<T>(this IEnumerable<T> source)
{
List<T> distinctValues = new List<T>();
foreach (T val in source)
{
if (!distinctValues.Contains(val))
{
distinctValues.Add(val);
}
}
return (IEnumerable<T>)distinctValues;
}
}
And to get the distinct values:
string[] newstr = str.DistinctNonBuiltIn().ToArray();
Hope this helps.