I am using an interface in C# and rather than write an entirely new class which implements that interface is it possible to just create an object which implements that interface? The interface is defined as
public interface ITokenStore
{
IToken CreateRequestToken(IOAuthContext context);
IToken CreateAccessToken(IOAuthContext context);
}
And I know in java I could something like
ITokenStore tokenStore = new ITokenStore()
{
IToken CreateRequestToken(IOAuthContext context) {
IToken requestToken = null;
return requestToken;
}
IToken CreateAccessToken(IOAuthToken context) {
IToken accessToken = null;
return accessToken;
}
};
Is there an equivalent way to instantiate in instance of an interface in c#?
解决方案
The only way to "Create an instance of a interface in c#" is to create an instance of a type implementing the interface.