Am o clasa ca atare:
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));
}
}
Practic clasa este un cuvânt, și dacă este sau nu a fost găsit în căutare.
Așa că am crea o listă de această clasă ca atare:
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 });
Atunci când am căuta în listă pentru a vedea dacă acesta conține un cuvânt, vreau să setați toate wordIsFound valori de la 1 acolo unde este cazul. Unele cuvinte în listă ar putea fi la fel.
Deci ceva de genul
string wordSearch = "test";
if (wordsIn.Exists(x => x.wordTxt == wordSearch)) {
//set all wordIsFound = 1 where word matches wordSearch
}
Așa cum am stabilit wordIsFound la 1 la 1 și al 3-lea element din lista (pe cele care se potrivesc wordSearch ?