Böyle bir dersim var.:
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));
}
}
Temelde sınıfı bir kelime, ya da bir arama tespit edilmiştir.
Bu yüzden bu sınıfın bir listesini böyle oluşturuyorum:
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 });
Ardından, bir kelime içerip içermediğini görmek için listeyi aradığımda, uygun olduğunda tüm wordİsFound değerlerini 1 olarak ayarlamak istiyorum. Listedeki bazı kelimeler aynı olabilir.
Yani şöyle bir şey
string wordSearch = "test";
if (wordsIn.Exists(x => x.wordTxt == wordSearch)) {
//set all wordIsFound = 1 where word matches wordSearch
}
Peki, listedeki 1. ve 3. öğede (wordSearch ile eşleşenler) wordisfound'u 1'e nasıl ayarlayabilirim ?