Question: ### Question

I've now read a lot about Duck Typing, and I seem to understand the concept.

What I've not understood is, in what case it does effectively make sense to abandon the benefits of strong typified programming to the benefits of Duck Typing. *In what case would one use Duck Typing instead of Interfaces and Inheritance?*

I mean if you anyway need to secure that an object passed to a Method implements certain methods, why shouldn't I simply define an Interface?

Just to be clear, I know how Duck Typing works. I want to know when it really makes sense to use it.

### Clarification:

In which case would you use

```
public bool MyMethod(dynamic obj)

```

instead of

```
public bool MyMethod(ISomeInterface obj)
//or
public bool MyMethod(SomeBaseClass obj)

```

Answer: 
Duck-typing is used a lot in C#, you're just unaware of it most of the time. The compiler uses it a lot under the cover, for `foreach` statements, for Linq, for `await`and for collection initializers. This [question](https://stackoverflow.com/questions/6368967/duck-typing-in-the-c-sharp-compiler) details it nicely.

The other way for you to use duck typing is with the `dynamic` keyword. And let's be franc, you should avoid it as much as possible. But it's very useful to interoperate with dynamic languages/contexts. For instance, suppose you're calling a web service that answers with poorly defined json (so you can't deserialize it easily to a known class). It might be a lot easier for you toparse it as a `JObject` using [json.Net](http://www.newtonsoft.com/json), and use that `JObject` as a `dynamic`.

```
dynamic myParsedJson = JObject.Parse(json);
string theStringImLookingFor = myParsedJson.foo.bar.blah.nicestring;

```

Another use case is in ASP.net MVC Viewmodels. Having a dynamic viewmodel can be very powerful. The [Orchard CMS](http://www.orchardproject.net/) makes heavy use of it, and even thoug it's a little hard to wrap your head around it at first, it allows very powerful use cases.

COM interop comes to mind as well.
**Duck Typing:**

> 
> Please you do this rather than asking who you are.
> 
> 
> 

**Example:**

> 
> Here coding should be simply define and execution. Example, here are
>  the things that I want the following object do something.
> 
> 
> 

```
    Please("Walk", new Dog());
    Please("Run", new Duck());
    Please("Fly", new Cup());
    Please("Fly", new Bird());
    Please("Fly", new Man());
    Please("Walk", new Man());
    Please("Run", new Man());

```

> 
> This is the result after excuting test.
> 
> 
> 

[![enter image description here](https://i.stack.imgur.com/mTenN.jpg)](https://i.stack.imgur.com/mTenN.jpg)

> 
> So, the above objects will do things that we requesting to do only.
>  Additional, I have added the question to ask them answer who they,
>  too. Here is the code in C#.
> 
> 
> 

```
private void Please(string Action, object Obj)
{
    MethodInfo method = Obj.GetType().GetMethod(Action, Type.EmptyTypes, null);
    if (method != null)
    {
        method.Invoke(Obj, new object[] { });
    }
    else
    {
        Console.WriteLine(string.Format("I can not {0} because {1}", Action, WhoAreYou(Obj)));
    }
}

private string WhoAreYou(object unknown)
{
    string question = "WhoAreYou";
    MethodInfo whoAreYou = unknown.GetType().GetMethod(question, Type.EmptyTypes, null);
    return whoAreYou.Invoke(unknown, new object[] { }).ToString();
}

```