Results 1 to 5 of 5

Thread: Importance of c# Interfaces

  1. #1
    Join Date
    Nov 2009
    Posts
    57

    Importance of c# Interfaces

    Hello friends,
    I am last year computer science student. I recently started learning c# language. In our last lecture we learn about c# Interfaces, but I didn't understand it clearly. Can anyone tell me Importance of c# Interfaces.
    Thanks in advanced.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Importance of c# Interfaces

    I have written following program for you, in which I have use Interface. In following program I have defined the Itests.Class(Managers) as the one of the interface. I also create another class but I didn't declare it as interface. Just try to understand it.




    Code:
    public interface Itests
    {
        void DoSomethings();
    }
    
    public class Managers:Itests
    {
        public void DoSomething()
        {
            Console.WriteLine("test is started");
        }
    
    }
    class Employees
    {
        public void DoSomethings()
        {
            Console.WriteLine("test is over ");
        }
    }
    
    class Programs
    {
        static void Main(string[] args)
        {
            Manager ms = new Managers();
            ms.DoSomething();
            Employee es = new Employees();
            es.DoSomethings();
            Console.ReadLine();
        }
    }

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: Importance of c# Interfaces

    Using interface you can declare method in another interface without declaring new interface. But make sure that you have implement write interface otherwise it will give you error message. Using interface you can declare abstract methods in an abstract base class, because interface only gives description of method when you use this method in your program.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Importance of c# Interfaces

    Just try to understand following example. In this example I have use Interface. After learning following code you clearly understand concept of interface. To overcome multiple inheritance we use interface.



    Code:
    using System;
    
    namespace ConsoleApplication1
    {
       public class Mammals
       {
          protected string Characteristiss;
          public string characteristicss
          {
             get
             {
                return this.Characteristiss;
             }
             set
             {
                this.Characteristiss=value;
             }
          }
       }
       interface IIntelligences
       {
    
          bool intelligent_behavior();
       }
    
       class Humans: Mammals, IIntelligences
       {
          public Human()
          {
              characteristics = "Humans are mammalss";
          }
    
    
          public bool intelligent_behaviors()
          {
             Console.WriteLine("{0} and have intelligence",characteristics);
             return true
          }
       }
       class Whales: Mammals
       {
          public Whale()
          {
             characteristicss = "Whale are mammalss";
             Console.WriteLine("{0}",characteristics);
          }
       }
       class InterfaceApp
       {
          public static void Main(string[] args)
          {
             Whale whales = new Whale();
             Human humans = new Human();
          
             IIntelligence humanIQs = (IIntelligences)humans;
             humanIQs.intelligent_behaviors();
    
             Console.Reads();
          }
       }
    }

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: Importance of c# Interfaces

    To use multiple class in one program we use interface. First you have to declare one interface in each class. After that invoke each interface from each class, but make sure that they must have at least one method. For eg.
    Code:
           public Interface Animals
                {
                    public void Talks();
                    public void Eats();
                }
    now add another method.

    Code:
     public Interface Animals
                {
                    public void Talks();
                    public void Sleeps();
                    public void Eats();
                }

Similar Threads

  1. What are an interfaces to CRM applications
    By Deward in forum Technology & Internet
    Replies: 5
    Last Post: 14-02-2011, 05:31 PM
  2. Need the best audio interfaces
    By Cajetan in forum Hardware Peripherals
    Replies: 3
    Last Post: 08-02-2011, 06:02 AM
  3. Professional Soundcards/Interfaces
    By Ravana in forum Windows Software
    Replies: 8
    Last Post: 27-09-2010, 11:58 PM
  4. Problem with Inheritance and interfaces
    By TechGate in forum Software Development
    Replies: 5
    Last Post: 27-02-2010, 02:25 AM
  5. Interfaces in Java
    By cyber-noob in forum Software Development
    Replies: 3
    Last Post: 07-11-2009, 01:31 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,093,813.81379 seconds with 17 queries