The below code is list element.
List <string> lsLinks = new List<string>();
Before adding new strings i want to check whether list is containing the string i am going to add or not. How can i do that with most efficient way.
I can iterate through whole list and check but i think that would not be performance wise.
The most efficient way would be to simply use a
HashSet<T>, either instead of the list (if order doesn’t matter), or in addition to the list, if it does.i.e. either
or
You might also find a use for
.Distinct()in LINQ, i.e.