Predefined Interface exposes some method,we are using that method but interface doent have definition part ,then how its working in c#? -


interface exposes method,we using method in class interface doent have definition part ,then how working in c#. example

class productnamecomparer : icomparer {    public int compare(object x, object y)    {       product first = (product)x;       product second = (product)y;      return first.name.compareto(second.name);    } } 

here icomparer exposes compareto() method, icomparer doesn't have compareto() method definition part, how working?

interface contract declares method rather having implementation part....class implements particular interface should have implemenation detail.

for instance, have ianimal interface , dog class implements ianimal interface,

    public interface ianimal     {         void walk(); // declares method, not implemenation     }      //class implementing interface      //must define method specified in interface     class dog : ianimal     {         public void walk()         {             console.writeline("dog can walk");         }     } 

in example, misunderstood icomparer interface.

icomparer defines interface compare() method

whereas

compareto() declared icomparable interface.

in above code, have implemented icomparer interface so, defining compare() method details in productnamecomparer class.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -