Ho una classe in quanto tale:
public class cls_words : IEquatable<cls_words>
{
public int indx { get; set; }
public string wordTxt { get; set; }
public int wordIsFound { get; set; }
public override string ToString()
{
return "ID: " + wordIsFound + " Name: " + wordTxt;
}
public override bool Equals(object obj)
{
if (obj == null) return false;
cls_words objAsWord = obj as cls_words;
if (objAsWord == null) return false;
else return Equals(objAsWord);
}
public override int GetHashCode()
{
return wordIsFound;
}
public bool Equals(cls_words other)
{
if (other == null) return false;
return (this.wordIsFound.Equals(other.wordIsFound));
}
}
Fondamentalmente la classe è una parola, e se sia o non è stato trovato in una ricerca.
Così ho creato una lista di questa classe in quanto tale:
List<cls_words> wordsIn = new List<cls_words>();
wordsIn.Add(new cls_words { indx= 1, wordTxt = "test", wordIsFound=0 });
wordsIn.Add(new cls_words { indx= 2, wordTxt = "the", wordIsFound=0 });
wordsIn.Add(new cls_words { indx= 3, wordTxt = "test", wordIsFound=0 });
Quindi quando faccio una ricerca elenco per vedere se contiene una parola, voglio impostare tutti wordIsFound i valori di 1, ove appropriato. Alcune parole nell'elenco potrebbe essere lo stesso.
Quindi qualcosa di simile
string wordSearch = "test";
if (wordsIn.Exists(x => x.wordTxt == wordSearch)) {
//set all wordIsFound = 1 where word matches wordSearch
}
Così come ho impostato wordIsFound a 1 su 1 ° e 3 ° elemento della lista (quelli che corrispondono a wordSearch ?