Mam klasę jako takie:
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));
}
}
W zasadzie klasa-to słowo, i niezależnie od tego, czy było ono znalezione podczas wyszukiwania lub nie.
Dlatego tworzę listę tej klasy jako takie:
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 });
Następnie, gdy przeglądam listę, aby dowiedzieć się, czy zawiera on słowa, chcę zainstalować wszystkie znalezione wartości wordIsFound równe 1, gdzie jest to właściwe. Niektóre słowa w liście mogą być takie same.
Więc coś w tym rodzaju
string wordSearch = "test";
if (wordsIn.Exists(x => x.wordTxt == wordSearch)) {
//set all wordIsFound = 1 where word matches wordSearch
}
Tak więc, jak zainstalowałem wartość wordIsFound równy 1 dla 1-go i 3-go miejsca na liście (te, które pasują do wyszukiwania słów ?