Need help with C#

Discussion in 'Programming' started by moneycms, Mar 31, 2010.

  1. #1
    I want to know what is an interface in C#. How will they help
     
    moneycms, Mar 31, 2010 IP
  2. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #2
    it helps implement a defined method
     
    gapz101, Mar 31, 2010 IP
  3. matessim

    matessim Active Member

    Messages:
    514
    Likes Received:
    5
    Best Answers:
    1
    Trophy Points:
    70
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #3
    Interfaces make it possible to work on huge projects, when your less interested in how another part of a big code works, but you need to know how to use it.
     
    matessim, Mar 31, 2010 IP
  4. EgyptGuy

    EgyptGuy Peon

    Messages:
    167
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #4
    An interface contains only the signatures of methods, delegates or events. The implementation of the methods is done in the class that implements the interface
     
    EgyptGuy, Mar 31, 2010 IP
  5. johnedwards

    johnedwards Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #5
    It is easiest method.
     
    johnedwards, Apr 7, 2010 IP
  6. dreteh

    dreteh Member

    Messages:
    514
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    33
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #6
    Here is my example:

    interface Vehicle {
    void StartEngine();
    }

    class HondaCivic implements Vehicle{
    function StartEngine(){
    implementation ....
    }
    }

    class ToyotaCorolla implements Vehicle{
    function StartEngine(){
    implementation ....
    }
    }

    void Main(){
    {
    function GoToWork(Vehicle myCar) {
    myCar.StartEngine();
    }
    }

    Look at the example above.
    Without the Vehicle interface you will need one GoToWork function with HondaCivic type parameter, and one with ToyotaCorolla type parameter.
    But if both HondaCivic and ToyotaCollora implement Vehicle interface, than GoToWork can takes in a Vehicle type parameter.
     
    dreteh, Apr 7, 2010 IP