Q:

In C#, what is the benefit of assigning a class variable to an interface variable before calling any methods?

Where I work we develop in C# .NET and I was looking a code that they have made (my job is to optimize it) but I saw something in particular:
Assuming that InterfaceDHO is an interface and ClassDHO is a class that implements InterfaceDHO.
Code:
InterfaceDHO in1;
ClassDHO cl1 = new ClassDHO();

in1 = cl1;

in1.METHODHERE(ARG HERE, ARG2 HERE);

Why are they doing this? Why assign the ClassDHO instance to an interface?

A:

If ClassDHO implements InterfaceDHO as follows:
class ClassDHO : InterfaceDHO
{
    void InterfaceDHO.METHODHERE(arg1, arg2) ...
}

then METHODHERE is what's termed an explicit interface implementation, and it can only be accessed via a variable of type InterfaceDHO. The code you show is a little long-winded, but handles that situation. It could be simplied to the following though:
InterfaceDHO in1 = new ClassDHO();

in1.METHODHERE(ARG HERE, ARG2 HERE);

However, if this is not the case, then the following code will, at least for the small snippet you provide, have the same affect:
var in1 = new ClassDHO();  // in1 will be of type ClassDHO

in1.METHODHERE(ARG HERE, ARG2 HERE);

In other words, the interface variable isn't required.
You provide very little code though and in1 may be used in other ways later in the code (or you may have missed bits out), so it's not possible to say for sure.

A:

There is no such thing as an instantiation of an interface.  Interfaces are implemented by classes.  Classes are instantiated.  References are held, either to classes, or to interfaces.
What you are witnessing is (probably) a programmer trying to adhere to the (very good) principle called Program To The Interface, Not To An Implementation.  See:

http://www.fatagnus.com/program-to-an-interface-not-an-implementation/
https://stackoverflow.com/questions/383947/what-does-it-mean-to-program-to-an-interface

So, if the lines that you have shown are the actual code, then this programmer may be a bit confused.  But if the lines that you are showing us have been picked up from different places in the code, (as the blank lines seem to suggest discontinuities in the code listing,) then what is happening is that the code that makes the method call does not want to know anything about the implementation (ClassDHO), it only wants to work with the interface (InterfaceDHO).

A:

It is possible that ClassDHO doesn't actually implement InterfaceDHO, and the code is doing an implicit conversion (though I don't think that extra step is necessary even then).
It is possible that there used to be different implementations of the interface in that code, so it made sense to split up the variables, but when the others were removed this code wasn't cleaned up.
More likely though, the code was simply written by someone who was bad at programming.

