C# interface instance-like

to work with a library I just found I need to implement a few interfaces first. But some methods seem to be asking for objects that have the type of some interfaces... And if I have an interface called MyInterface I can write things like :

    MyInterface shoe;

It does not really make sense to me. Can somebody teach me this concept ?

Then i have found out very nice solution about C# Inerface, Interfaces establish a contract between a class and the code that calls it. They also allow you to have similar classes that implement the same interface but do different actions or events and not have to know which you are actually working with. This might make more sense as an example so let me use same example as per your link with bit of modification:

using System; 
 
interface IPerl 
{ 
    void Read(); 
} 
 
class Test : IPerl 
{ 
    public void Read() 
    { 
    Console.WriteLine("Read Test"); 
    } 
} 
 
class Test1 : IPerl 
{ 
    public void Read() 
    { 
    Console.WriteLine("Read Test1"); 
    } 
} 
 
class Program 
{ 
    static void Main() 
    { 
    IPerl perl = new Test(); // Create instance of Test. 
    perl.Read(); // Call method on interface output will be different then Test1. 
 
        perl = new Test1(); // Create instance of Test1. 
    perl.Read(); // Call method on interface output will be different then Test. 
 
    } 
} 

Output:

  1. "Read Test"
  2. "Read Test1"

I hope this would help.

4 comments on “C# interface instance-like”

  1. Gravatar of rolex explorer replica  rolex explorer replica
    Posted Sunday, December 9, 2012 at 12:40:12 AM

    Then i have found out very nice solution about C# Inerface

  2. Gravatar of Ugg Boots UK  Ugg Boots UK
    Posted Friday, December 14, 2012 at 11:37:04 PM

    This might make more sense as an example so let me use same example as per your link with bit of modification

  3. Gravatar of isabel marant sneakers  isabel marant sneakers
    Posted Tuesday, January 15, 2013 at 11:16:12 PM

    When they say you are definitely not proud of, so good, is not frustrated when they say that bad

  4. Gravatar of rolex replica  rolex replica
    Posted Wednesday, March 27, 2013 at 9:00:33 PM

    To be able to overcome that misunderstandings along with problem one can just simply choose comprehensive inside selecting the best form of style.

Post a comment