Recently I've been asked by my friend why Dictionary<T, V>
explicitly implements ICollection<KeyValuePair<T, V>>
when it is already inherited by IDictionary<T,V>
?
I realized that I don't know the answer as well. Here are the links to official documentation:
Dictionary<T, V>
- http://msdn.microsoft.com/en-us/library/xfhwa508(v=vs.110).aspx
IDictionary<T,V>
- http://msdn.microsoft.com/en-us/library/s4ys34ea(v=vs.110).aspx
Is there any specific reason why it was done like that? Is there a specific architecture pattern or anything?
This appears to simply be a case of showing all of the implemented interfaces implicitly.
I made this following example to test this. My source code is:
public class Class1 : ITest
{
public void Testing()
{
Console.WriteLine("Test");
}
public void Testing2()
{
Console.WriteLine("Test2");
}
}
public interface ITest : ITest2
{
void Testing();
}
public interface ITest2
{
void Testing2();
}
Now going in to Reflector.Net and decompiling I get this:
public class Class1 : ITest, ITest2
{
public void Testing()
{
Console.WriteLine("Test");
}
public void Testing2()
{
Console.WriteLine("Test2");
}
}
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