c# - Extension methods not showing even on implementing IEnumerable -
this code:
class myclass : ienumerable { public dictionary<int, string> dctidname = new dictionary<int, string>(); public myclass() { (int idx = 0; idx < 100; idx++) { dctidname.add(idx, string.format("item{0}", idx)); } } // ienumerable member public ienumerator getenumerator() { foreach (object o in dctidname) { yield return o; } } } where create object of class , use in manner not linq extension methods where, count, etc.
myclass obj = new myclass(); var d = obj.where( x => x.key == 10); //<-- error here the namespaces have included are:
using system; using system.collections; using system.collections.generic; using system.componentmodel; using system.data; using system.diagnostics; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; using system.xml.linq; how fix this?
it does work. asparallel extension method on ienumerable. extension methods though work on ienumerable<t>. class should start this:
class myclass : ienumerable<sometype> or:
class myclass<t> : ienumerable<t> (where t type of generic type argument)
class myclass : ienumerable<keyvaluepair<int, string>> { public dictionary<int, string> dctidname = new dictionary<int, string>(); public myclass() { (int idx = 0; idx < 100; idx++) { dctidname.add(idx, string.format("item{0}", idx)); } } // ienumerable member public ienumerator<keyvaluepair<int, string>> getenumerator() { foreach (keyvaluepair<int, string> o in dctidname) { yield return o; } } ienumerator ienumerable.getenumerator() { return this.getenumerator(); } } now can call select example.

Comments
Post a Comment