Does List.Contains(mystring) do a reference comparison or a value comparison? Eg I have this code:
/// <summary>
/// If the value isn't null or an empty string,
/// and doesn't exist in the list, it adds it to the list
/// </summary>
static void AddToListIfNotEmpty(List<string> thelist, SqlString val)
{
string value = val.ToString().Trim();
if (!string.IsNullOrEmpty(value))
{
bool found = false;
foreach (string x in thelist) if (x == value) found = true;
if (!found) thelist.Add(value);
}
}
Can i simplify the foreach and following line to:
if (!thelist.Contains(value)) thelist.Add(value);
Thanks