c# - What is this compiler error with generics -


i getting compiler error:

the type 'generics.widget' cannot used type parameter 't' in generic type or method 'generics.mygenerics.maximum<t>(t, t, t)'. there no implicit reference conversion 'generics.widget' 'system.icomparable<generics.widget>'

see attached screen shot compiler error in code trying use class.

    using system;     using system.collections.generic;     using system.linq;     using system.text;     using system.threading.tasks;      namespace generics {         // class implements icomparable         class widget : system.icomparable {             private string name;              public widget(string name) {                 this.name = name;             }              int system.icomparable.compareto(object obj) {                 return name.compareto(((widget)obj).name);             }          }     } 

screen shot of compiler error

you need implement generic version of icomparable

public interface icomparable<in t>   class widget : system.icomparable<widget> {     public int compareto(widget other)     {         throw new notimplementedexception();     }     } 

you haven't shown maximum method has constraint on t

where t : icomparable<widget> 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -