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

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

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

laravel - Undefined property: Illuminate\Pagination\LengthAwarePaginator::$id (View: F:\project\resources\views\admin\carousels\index.blade.php) -