所以我有这个用 .NET 4.7 编译的最小示例:
class Program
{
static void Main(string[] args)
{
IDictionary<int, string> dic = new ConcurrentDictionary<int, string>();
ConcurrentDictionary<int, string> sameDic = (ConcurrentDictionary<int, string>) dic;
dic.Add(1, "Hold");
dic.Add(2, "position");
dic.Remove(1); // OK
sameDic.Remove(2); // Not even compiling !!
}
}
- 那么打电话安全
dic.Remove(1)吗? - 知道编译器不接受以下代码,如何重现相同的行为?
代码 :
public interface IFoo
{
void B();
}
public class Bar : IFoo
{
private void B() // Not allowed
{
}
}