I'm currently studying for my MS 70-515 exam. In one of the practices the author implements an interface both implicit as well as explicit. The explicit implementation just calls the implicit implementation. The explicit implementation is just listed without an explanation.
Does it make sense to have both an implicit and an explicit implementation of the interface? I would think the explicit implementation is redundant (in this case).
public class PassTextBox : TextBox, IScriptControl
{
public virtual IEnumerable<ScriptDescriptor> GetScriptDescriptors()
{
var descriptor = new ScriptControlDescriptor(
"AjaxEnabled.PassTextBox", ClientID);
// ...
return new ScriptDescriptor[] {descriptor};
}
IEnumerable<ScriptDescriptor> IScriptControl.GetScriptDescriptors()
{
return GetScriptDescriptors();
}
}
BTW, the code seems to run just fine without the explicit implementation, as the implicit implementation is public.
It concerns MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4 Chapter 9, Lesson 2, Practice 3 to be precise.
The explicit implementation seems to be totally superfluous.
I can't think of a way to call it where it would make a difference if you left it out.
There is one small difference, the implicit version is virtual meaning it could be overridden. The explicit version will always be called at this entry point. But since it only calls the virtual member that difference is not used here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With