Hello,

Im having this problem with public interface, i want to use this method (is on a .dll)

namespace DS.GS.Admin
{
    public interface BrokerAdmin
    {
        int GetCount();
     }

But i dont know how to call it, I try:

DS.GS.Admin.BrokerAdmin ba;
int a = ba.GetCount(); -> Error

And:
DS.GS.Admin.BrokerAdmin ba = new DS.GS.Admin.BrokerAdmin(); -> Error

And:
int a = DS.GS.Admin.BrokerAdmin.GetCount(); -> Error


Those are my first steps whit C# and i really appreciate all the help you gave me.

Thanks.

An interface is just that: an interface. You need to implement it in another class, then you can use it through that class:

public class Foo: DS.GS.Admin.BrokerAdmin {
  public int GetCount() {
    return 12345;
  }
}
Foo foo = new Foo();
BrokerAdmin ba = foo;

Console.WriteLine( ba.GetCount() );

And for future reference, interfaces are conventionally prefixed with I so that they're more easily identified. Your interface would become IBrokerAdmin under that idiom.

Hello,

Im having this problem with public interface, i want to use this method (is on a .dll)

namespace DS.GS.Admin
{
    public interface BrokerAdmin
    {
        int GetCount();
     }

But i dont know how to call it, I try:

DS.GS.Admin.BrokerAdmin ba;
int a = ba.GetCount(); -> Error

And:
DS.GS.Admin.BrokerAdmin ba = new DS.GS.Admin.BrokerAdmin(); -> Error

And:
int a = DS.GS.Admin.BrokerAdmin.GetCount(); -> Error


Those are my first steps whit C# and i really appreciate all the help you gave me.

Thanks.

Interface is collection of un-implemented methods. The interface itself does not provide implementations for the members that it defines. The interface simply specifies the members that must be supplied by classes that implement the interface.

Implementation relationship exists when a class declares that it implements an interface and the class implements all the members of the interface. A class that implements a particular interface is convertible to that interface, so such types support certain methods without an inheritance relationship.

Please follows Narue's Example.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.