यह ठीक है जो ट्रॉय मैग्नीस द्वारा "LINQ to Objects Using C# 4.0" में प्रदर्शित किया गया है।
संपादित करें: उदाहरण टिड-बिट्स और स्पष्टीकरण जोड़ना: लेखक का उदाहरण LINQ से SQL के बजाय ऑब्जेक्ट्स के लिए है। लेखक बस एसक्यूएल सर्वर पर एक IEqualityComparer, जिनमें से कुछ टुकड़े इस तरह देखा ...
public class SoundexEqualityComparer : IEqualityComparer<string>
{
public bool Equals(string x, string y)
{
return GetHashCode(x) == GetHashCode(y);
}
public int GetHashCode(string obj)
{
//e.g. convert soundex code A123,
//to an integer: 65123
int result = 0;
string s = soundex(obj);
if (string.IsNullOrEmpty(s) == false)
result = Convert.ToInt32(s[0]) * 1000 +
Convert.ToInt32(s.Substring(1, 3));
return result;
}
private string soundex(string s)
{
//e.g. book's implementation omitted for this post.
}
}
//example usage (assuming an array of strings in "names")
var q = names.GroupBy(s => s, new SoundexEqualityComparer());
स्रोत
2010-06-07 20:58:42
उन लोगों के लिए जिन्होंने नए संस्करणों के साथ प्रयास किया: (और मेरे अपने भविष्य के संदर्भ के लिए) [डीबीफंक्शन ("एसक्यूएलएसवर", "सोंडेक्स")] –