C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




using interface in c# winforms


Posted Date: 07 Oct 2008      Total Responses: 3

Posted By: CRPRAJAN       Member Level: Gold     Points: 1


Can anybody explain me the concept of interface with a sample code using c# winform application?

I don't want the code to be written in a console application

Thanx in advance




Responses

Author: R O B I N    07 Oct 2008Member Level: GoldRating:     Points: -20
you can use the example like:

interface IMyInterface
{
void MethodToImplement();
}

class InterfaceImplementer : IMyInterface
{
static void Main()
{
InterfaceImplementer iImp = new InterfaceImplementer();
iImp.MethodToImplement();
}

public void MethodToImplement()
{
Console.WriteLine("MethodToImplement() called.");
}
}


It is an simple example to implement the interface


Author: loki    07 Oct 2008Member Level: BronzeRating:     Points: -20
Hi,

Interface implementation can be confusing...

I see a feature in C# that can be very confusing. In the example below we have a class (Test) that implements 2 interfaces (I1 and I2). So the logic says that we should have implementations in the class Test for both MyFunction() methods from I1 and I2. BUT! As you see in the example below everything works fine with only 1 implementation. This is not as correct as we expect, because we can't be sure which of the two interfaces is implemented in the MyFunction method in class Test. So the solution is in another example (EXAMPLE2). In Example2 MyFunction() is implemented in class Test for each interface, by using a different method. (I1.MyFunction() -> for I1, I2.MyFunction() -> for I2).

//EXAMPLE 1
using System;

namespace PavelTsekov
{
interface I1
{
void MyFunction();
}
interface I2
{
void MyFunction();
}
class Test : I1,I2
{
public void MyFunction()
{
Console.WriteLine("Guess which interface I represent???!");
}
}
class AppClass
{
public static void Main(string[] args)
{
Test t=new Test();
I1 i1=(I1)t;
i1.MyFunction();
I2 i2=(I2)t;
i2.MyFunction();
}
}
}

//EXAMPLE 2
using System;

namespace PavelTsekov
{
interface I1
{
void MyFunction();
}
interface I2
{
void MyFunction();
}
class Test : I1,I2
{
void I1.MyFunction()
{
Console.WriteLine("Now I can say this here is I1 implemented!");
}
void I2.MyFunction()
{
Console.WriteLine("Now I can say this here is I2 implemented!");
}
}
class AppClass
{
public static void Main(string[] args)
{
Test t=new Test();
I1 i1=(I1)t;
i1.MyFunction();
I2 i2=(I2)t;
i2.MyFunction();
}
}
}



Loki.


Author: Meetu Choudhary    23 Oct 2008Member Level: GoldRating:     Points: 6
Hi,

Interface

A standard way of calling routines and passing data structures. For example, the interface between two layers of code might be expressed in terms of routines that pass and return a particular data structure. Linux's VFS is a good example of an interface.

An interface in the programming language is an abstract type that is used to specify an interface (in the generic sense of the term) that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signatures and constant declarations (variable declarations which are declared to be both static and final). An interface may never contain method definitions.

As interfaces are implicitly abstract, they cannot be directly instantiated. Object references may be specified to be of an interface type; in which case they must either be null, or be bound to an object which implements the interface.

The keyword implements is used to declare that a given class implements an interface. A class which implements an interface must either implement all methods in the interface, or be an abstract class.

One benefit of using interfaces is that they simulate multiple inheritance.


for more information please visit

http://en.wikipedia.org/wiki/Interface_(Java)

==
Thanks and Regards
Meetu Choudhary



Post Reply
You must Sign In to post a response.
Next : What are the Good Qualities of a Developer??
Previous : LOGIN Page
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

doors in nj

Contact Us    Privacy Policy    Terms Of Use