Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Query regarding IEnumerable [modified] - Stupid question

Query regarding IEnumerable [modified] - Stupid question

Scheduled Pinned Locked Moved C#
questiondatabase
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dan sh
    wrote on last edited by
    #1

    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

    P P N 3 Replies Last reply
    0
    • D dan sh

      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

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      It's possible for a class to have a GetEnumerator method without actually implementing IEnumerable.

      1 Reply Last reply
      0
      • D dan sh

        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

        P Offline
        P Offline
        PaulLinton
        wrote on last edited by
        #3

        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.

        D 1 Reply Last reply
        0
        • P PaulLinton

          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.

          D Offline
          D Offline
          dan sh
          wrote on last edited by
          #4

          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.

          P 1 Reply Last reply
          0
          • D dan sh

            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

            N Offline
            N Offline
            N a v a n e e t h
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • D dan sh

              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.

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #6

              Nothing "comes with" an interface.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups