Query regarding IEnumerable [modified] - Stupid question
-
Take a look at this question: If a class does not implements IEnumerable interface,which of the following is cannot be used? a. GetEnumerator() b. ForEach I had to choose one option and I think both are true. Am I correct? (It was an online test on a widely used website)
modified on Tuesday, July 8, 2008 1:19 AM
-
Take a look at this question: If a class does not implements IEnumerable interface,which of the following is cannot be used? a. GetEnumerator() b. ForEach I had to choose one option and I think both are true. Am I correct? (It was an online test on a widely used website)
modified on Tuesday, July 8, 2008 1:19 AM
I can create a method on any class called GetEnumerator(), it doesn't have to have anything to do with IEnumerable. Eg public class DumbClass { public string GetEnumerator() { return "Good morning";} } Not very useful but now I can say DumbClass x = new DumbClass(); Console.WriteLine(x.GetEnumerator()); ForEach needs an implementation of IEnumerable.
-
Take a look at this question: If a class does not implements IEnumerable interface,which of the following is cannot be used? a. GetEnumerator() b. ForEach I had to choose one option and I think both are true. Am I correct? (It was an online test on a widely used website)
modified on Tuesday, July 8, 2008 1:19 AM
It's possible for a class to have a GetEnumerator method without actually implementing IEnumerable.
-
I can create a method on any class called GetEnumerator(), it doesn't have to have anything to do with IEnumerable. Eg public class DumbClass { public string GetEnumerator() { return "Good morning";} } Not very useful but now I can say DumbClass x = new DumbClass(); Console.WriteLine(x.GetEnumerator()); ForEach needs an implementation of IEnumerable.
-
Take a look at this question: If a class does not implements IEnumerable interface,which of the following is cannot be used? a. GetEnumerator() b. ForEach I had to choose one option and I think both are true. Am I correct? (It was an online test on a widely used website)
modified on Tuesday, July 8, 2008 1:19 AM
d@nish wrote:
ForEach
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
PaulLinton wrote:
I can create a method on any class called GetEnumerator(), it doesn't have to have anything to do with IEnumerable
I meant the one that comes with the interface.
Nothing "comes with" an interface.