How to implement IComparer in C# for an interface -


i have interface named iemployee. need implement icomparer implementation of interface.

here code,

interface iemployee   {        string name {get;set;}       datetime dob {get;set;}   } 

i have created child class like

class employee   {        string name {get;set;}       datetime dob {get;set;}   } 

now need implement icomparer this, , in main want copmarer like

icomparer<iemployee> comparerobject= // comparer class. 

and using comparer need sort collection of employee based on names, like

var employees = new iemployee[]{new employee("....."),....} array.sort<iemployee>(employees , comparer); 

you instead implement icomparable. code like:

interface iemployee : icomparable {     string name { get; set; }     datetime dob { get; set; } }  class employee : iemployee {     public string name { get; set; }     public datetime dob { get; set; }      public int compareto(object obj)     {         return this.name.compareto(((iemployee)obj).name);     } } 

then can sort array follows:

array.sort<iemployee>(employees); 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -