Say I have 2 classes that inherit from the same interface.

class Foo : ISomeInterface
        {
            int a;
            int b;
        }

        class Bar : ISomeInterface
        {
            float a;
            float b;
        }

Is there anyway I can create a method that automatically recognises the original class without casting but can take any class that inherits from ISomeInterface?

public void Method(ISomeInterface input)
        {
            // If Foo is input then one method is called
            // If Bar is input then another method is called
        }

EDIT:

I'm trying to avoid the "is" keyword.

Hello,
since interfaces doesn't have a GetType method, you can use something like this:

if (input.GetType() == typeof(Bar))

Just a thought in a loud .. are you sure that it's really needed. Maybe there's a better approach for your problem?

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.