Results 1 to 7 of 7

Thread: Interface in C sharp

  1. #1
    Join Date
    Dec 2009
    Posts
    17

    Interface in C sharp

    I am beginner programmer in programming language world. I am learning the programming languages like C sharp, C++, Core Java, DBMS and .NET. I do programming on my DELL Studio 19 with Windows XP as operating system. Recently i was doing programming in C sharp (the basics one) and i came across a query that how to use interface in our program and what are its advantages and disadvantages?

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

    Re: Interface in C sharp

    I would say that the interface are similar to class, but not the class. They only looks like a class, but has no implementation. The definition of events, indexers methods and properties is all what is contains and nothing else.The main motto of using the interfaces is only to provide definitions is because they will get inherited by classes and structs(i.e structure), which must provide an implementation for each interface member defined.

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

    Re: Interface in C sharp

    I have some issue or problem related to interface in C sharp. The problem is if we don't force all the elements of the particular interface then what would happen when a missing element was called? code is shown below for this:
    interface foreach(ITemp tmp in myCollection)
    {
    string name = tmp.GetName();
    }
    PLease help me out for this problem.

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

    Re: Interface in C sharp

    The main thing you should know that the interface in C sharp are introduce as a replace/backup for achieving the multiple-inheritance. This is because the C sharp is not able achieve the multiple inheritance directly. So in order to achieve the multiple inheritance by some or the other way, they introduce the interface, so that we can inherit/inheriting the behavior of more than 1 class, avoiding the problem of name ambiguity that is found in C++.

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

    Re: Interface in C sharp

    My studies about the Interface says that, this interfaces in C sharp are similar in to class in definition matter but it has huge difference when consider its working. Always note that interface will be not be able to directly instantiated as an object. Non of the data members of the program can be defined in an interface. Only the methods and properties can be declared, and note not defined. e.g of simple interface:
    interface ShapeCircle
    {
    void DrawCircle();
    double area { get; set; }
    double radius { get; set; }
    }
    Hope you will able get enough knowledge about interface.

  6. #6
    softtrickseo Guest

    Re: Interface in C sharp

    The key to understanding interfaces might be to compare them with classes. Classes are objects that have properties and methods that act on those properties. While classes do exhibit some behavioral characteristics (methods), classes are things as opposed to behaviors, and that's how interfaces come in. Interfaces enable you to define behavioral characteristics, or abilities, and apply those behaviors to classes irrespective of the class hierarchy. For example, say that you have a distribution application in which some of the entities can be serialized. These might include the Customer, Supplier and Invoice classes. Some other classes, such as MaintenanceView and Document,might not be defined as serializable. How would you make only the classes you choose serializable? One obvious way would be to create a base class called something like Serializable. However, that approach has a major drawback. A single inheritance path won't work because we don't want all the behaviors of the class to be shared. C# doesn't support multiple inheritance, so there's no way to have a given class selectively derive from multiple classes. The answer is interfaces. Interfaces give you the ability to define a set of semantically related methods and properties that selected classes can implement regardless of the class hierarchy.

  7. #7
    Join Date
    Nov 2005
    Posts
    1,323

    Re: Interface in C sharp

    According to what knowledge i got of interface is that an Interface is a consider as reference type and it has abstract member's only. This interfaces can have the events, methods, properties and indexers as well, but keep in ind that an interfaces can only has declaration parts of all this. Any implementation must be placed in class that realizes them. Also note that an interface cannot have constants, data fields, constructors, destructors and static members. All the member declarations inside interface are implicitly public.
    Example :
    interface Rect
    {

    double length
    {
    get;
    set;
    }


    double breadth
    {
    get;
    set;
    }

    double CalculateRectArea();
    double CalculateRectVolume()

    }

Similar Threads

  1. Replies: 7
    Last Post: 22-10-2011, 10:35 PM
  2. Sharp 007SH Hybrid An 3D Clamshell Android Phone by Sharp
    By jackalz in forum Web News & Trends
    Replies: 3
    Last Post: 22-05-2011, 07:28 AM
  3. C sharp v/s C plus plus
    By GlassFish in forum Software Development
    Replies: 3
    Last Post: 30-01-2011, 07:06 AM
  4. Use of delegates in C sharp
    By opaper in forum Software Development
    Replies: 5
    Last Post: 25-01-2010, 01:44 PM
  5. Are Sharp LCD TV's better than Sanyo
    By SamSanite in forum Monitor & Video Cards
    Replies: 3
    Last Post: 06-08-2009, 09:44 AM

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,713,908,502.13282 seconds with 17 queries