IEnumerable.GetEnumerator() and IEnumerable.GetEnumerator()?

They don't because they compile one version as an Explicit Interface Method Implementation. It looks like this: public class SomeClassThatIsIEnumerable : IEnumerable { public IEnumerator GetEnumerator() { // return enumerator. } IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable)this).GetEnumerator(); } } What this type of construct does is make the first GetEnumerator method become the default method, while the other GetEnumerator method is only accessible if the caller first casts SomeClassThatIsIEnumerable to the type IEnumerator, so it avoids the problem Edit: based on the supplement above, you would want to use the new keyword: public interface IMyInterface { object GetObject(); } public interface IMyInterface : IMyInterface { new T GetObject(); } // implementation: public class MyClass : IMyInterface { public string GetObject() { return "howdy!"; } object IMyInterface.GetObject() { return GetObject(); } }.

They don't because they compile one version as an Explicit Interface Method Implementation. It looks like this: public class SomeClassThatIsIEnumerable : IEnumerable { public IEnumerator GetEnumerator() { // return enumerator. } IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable)this).GetEnumerator(); } } What this type of construct does is make the first GetEnumerator method become the default method, while the other GetEnumerator method is only accessible if the caller first casts SomeClassThatIsIEnumerable to the type IEnumerator, so it avoids the problem.

Edit: based on the supplement above, you would want to use the new keyword: public interface IMyInterface { object GetObject(); } public interface IMyInterface : IMyInterface { new T GetObject(); } // implementation: public class MyClass : IMyInterface { public string GetObject() { return "howdy! "; } object IMyInterface.GetObject() { return GetObject(); } }.

I'm not saying this, please see my "Supplement" in the post. Thanks :) – Dylan Lin Mar 15 '10 at 11:54 +1 even though you can't specify access level for an explicit interface implementation – erikkallen Mar 15 '10 at 12:18 @Dylan: Use the new keyword as the compiler recommends. See my edits above.

– David Morton Mar 15 '10 at 12:18 That works, thanks. But when we check the IEnumerable source code using Reflector, there's no new keywords, so why the BCL team didn't use the "new" keyword? – Dylan Lin Mar 15 '10 at 14:12 1 Reflector doesn't show the new keyword.It's there for C# compilation only.

That part of the BCL might not have been written in C# anyways. Remember, the compiler warning is a compiler warning from C#, not from the . NET Framework in general.

Try compiling the second block of code I showed above. When you open it in Reflector, the "new" keyword is gone. – David Morton Mar 15 '10 at 14:39.

The difference is that IEnumerable and IEnumerable are interfaces. In a concrete type, that implements both interfaces, at least one of them has to be implemented explicitly. In a concrete type inheritance you must use the new keyword to indicate that you want to overwrite the method from the base type.

When appplying the new keyword the method is not inherited. This means that myTypeInstance. Method will call the method defined on MyType, while ((MyBaseType) myTypeInstance).

Method will call the method defined on the base type. Public interface Interface1 { object GetItem(); } public interface Interface2 : Interface1 { T GetItem(); } public class MyBaseType : Interface1 { public object GetItem() { // implements Interface1.GetType() return null; } } public class MyType : Interface1, Interface2 { public new T GetItem() { // Implements Interface2.GetItem() return default(T); } object Interface1.GetItem() { // implements Interface1.GetItem() return this.GetItem(); // calls GetItem on MyType } } var myType = new MyType(); var myTypeResult = myType.GetItem(); // calls GetItem on MyType var myBaseTypeResult = new ((MyBaseType) myType).GetItem(); // calls GetItem on MyBaseType.

In my senario, the Interface2 inherits from Interface1, then you will get the compiler warning. – Dylan Lin Mar 15 '10 at 11:55 Should make no difference, as long as one of the GetItem methods is implemented explicitly, i.e. Using Interface.GetItem.

– Obalix Mar 15 '10 at 20:53 there will be a compiler warning, unless I use the "new" keyword. Please see my supplement in the post. :) – Dylan Lin Mar 16 '10 at 5:57.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions