c# - How to use a class as a generic -
i have class
public class client { ... } i have method uses generics:
public static t show<t>(dependencyobject sender, messageboxicon icon, string caption, observablecollection<t> datasource, messageboxbutton button) t : icomparable<t>, new() { ... } now, when want phone call in program:
customer customerselect = norubox.show<customer>(this, messageboxicon.box, "gridbox test", customerdata, noru.controls.messageboxbutton.selectcancel); i error tho. said type customer can't used type parameter t in show<t>(...). there no implicit reference conversion customer system.icomparable<customer>.
i tried public class client : icomparable , add together next class:
public int compareto(object obj) { var other = obj customer; if (other == null) homecoming 0; homecoming compareto(other); } but made no difference.
what aspect of each customer instance want compare? in illustration below, i'm assuming a holds key value.
public class client : icomparable<customer> { public int compareto(customer other) { if (other == null) homecoming 1; homecoming this.a.compareto(other.a); } } c# generics
No comments:
Post a Comment