Syntax to implement interfaces?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to extend the System.IAsynchResult so I created a class as follows:

public class MyAsynchResult : System.IAsyncResult
{
.....
}

But get:

C:\Inetpub\wwwroot\MyApp\MyAsynchResult.cs(8): 'MyAsynchResult' does not
implement interface member 'System.IAsyncResult.AsyncState' as well as for
each method of IAsynchResult.

I understand I have to implement each method, but I'm not sure of the syntax?
 
Dave,

There are two ways to implement an interface method. You are using the
IAsyncResult interface, so I will give a little bit of the definition here:

public interface IAsyncResult
{
object AsyncState {get;};
}

With that, you can implement the interface implicitly, meaning, you
define a public method which has the same signature:

public object AsyncState
{
get
{
// Return your result here.
}
}

Or, you can define the interface implementation explictly:

object IAsyncResult.AsyncState
{
get
{
// Return your result here.
}
}

They are pretty similar. The only difference is that with the explicit
implementation, you will have to cast your instance to a variable of that
type of interface in order to make the call to the property.

I have to ask, why are you implementing IAsyncResult yourself? You
shouldn't have to do this. What exactly are you trying to do?
 
There are two ways to implement interface methods - implicit and explicit:
1. (implicit) public void SomeInterfaceMethod(...)
2. (explicit) void System.IAsyncResult.SomeInterfaceMethod(...)
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant C++: C# to C++ Converter
Instant J#: VB.NET to J# Converter
 
Back
Top