J'ai une classe en tant que telle:
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));
}
}
Fondamentalement, la classe est un mot, et si oui ou non elle a été trouvée lors d'une recherche.
J'ai donc créer une liste de cette classe en tant que telle:
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 });
Puis, quand je recherche la liste pour voir si elle contient un mot, je veux mettre toutes les wordIsFound valeurs de 1, le cas échéant. Quelques mots dans la liste pourrait être la même.
Donc, quelque chose comme
string wordSearch = "test";
if (wordsIn.Exists(x => x.wordTxt == wordSearch)) {
//set all wordIsFound = 1 where word matches wordSearch
}
Alors, comment aurais-je mis wordIsFound à 1 sur le 1er et le 3ème élément de la liste (ceux qui correspondent aux mots cachés ?