Consider this code:
var someObject = GetSomeObject as ISomeInterface;
if (someObject != null)
{
// do someting, not only one method call with this object, so don't expect null propagation to be handy
someObject.CallSomeMethod();
}
Is that preferable over this:?
var someObject = GetSomeObject();
if (someObject is ISomeInterface)
{
// do someting
((ISomeInterface)someObject).CallSomeMethod();
}
What are the differences and when would I chose what to use?
Is it just about readability?