1

I recently watched a tutorial that declared an instance of a new object using the following method:

class exampleClass : IEnumerable
{
    //Class stuff...
}

class Main
{
    public void Method1
    {
        IEnumerable Obj1 = new exampleClass();
    }
}

I couldn't work out what the purpose or benefit of it was. I've always declared the type I will be instantiating so this way of doing it seemed alien.

Please could someone explain why you would do this and what the benefits are?

(The example above is purely to highlight the declaration of the new objects' type and then calling to instantiate a class of a different type.)

TheBadgerEB
  • 473
  • 1
  • 4
  • 10

0 Answers0