मुझे OrderBy()
जैसी विधि चाहिए जो हमेशा उच्चारण अक्षरों को अनदेखा करने और उन्हें गैर-उच्चारण की तरह देखने के लिए आदेश देता है। मैंने पहले ही OrderBy()
को ओवरराइड करने का प्रयास किया है लेकिन ऐसा लगता है कि मैं ऐसा नहीं कर सकता क्योंकि यह एक स्थिर विधि है।ऑर्डरबेटेड अक्षरों से अनदेखा
तो अब मैं OrderBy()
के लिए एक कस्टम लैम्ब्डा अभिव्यक्ति बनाना चाहते हैं, इस तरह:
public static IOrderedEnumerable<TSource> ToOrderBy<TSource, TKey>(
this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
{
if(source == null)
return null;
var seenKeys = new HashSet<TKey>();
var culture = new CultureInfo("pt-PT");
return source.OrderBy(element => seenKeys.Add(keySelector(element)),
StringComparer.Create(culture, false));
}
हालांकि, मैं इस त्रुटि हो रही है:
Error 2 The type arguments for method 'System.Linq.Enumerable.OrderBy<TSource,TKey>(System.Collections.Generic.IEnumerable<TSource>, System.Func<TSource,TKey>, System.Collections.Generic.IComparer<TKey>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
लगता है यह StringComparer
पसंद नहीं है । इसे कैसे हल किया जा सकता है?
नोट:
मैं पहले से ही here से RemoveDiacritics()
का उपयोग करने की कोशिश की, लेकिन मैं इस मामले में है कि विधि का उपयोग करने के लिए कैसे पता नहीं है। तो मैंने कुछ ऐसा करने की कोशिश की जैसे this जो भी अच्छा लगता है।
क्या आप Linq2Sql या LinqObjects का उपयोग कर रहे हैं? –
हैशसेट के लिए क्या है? – usr