string[] lines3 = new string[100];
List<string> lines2 = new List<string>();
lines3 = Regex.Split(s1, @"\s*,\s*");
if (!lines2.Contains(lines3.ToString()))
{
lines2.AddRange(lines3.Distinct().ToArray());
}
I have checked all the spaces etc but i still get duplicate values in my lines2 List
I have to remove my duplicate values here itself
Your this check:
is invalid. You are checking if your
lines2containsSystem.String[]sincelines3.ToString()will give you that. You need to check if item fromlines3exists inlines2or not.You can iterate each item in
lines3check if it exists in thelines2and then add it. Something like.Or if your
lines2is any empty list, then you can simply add thelines3distinct values to the list like:then your
lines2will contain distinct values.