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. Object unknown

Object unknown

Scheduled Pinned Locked Moved C#
questionhelp
2 Posts 2 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.
  • S Offline
    S Offline
    sharon
    wrote on last edited by
    #1

    Is there a way I can use an object without knowing which object it realy is? for exemple: I have several objects that implement IEnumerable(these objects has arrayList), I need to Implement IEnumerator and I want to do it once. but I don't know for which object I implement it for so when I do : object.arrayList[i] -its an error. (object doen't have an arrayList property). how can I do it??? thanks in advance , sharon

    J 1 Reply Last reply
    0
    • S sharon

      Is there a way I can use an object without knowing which object it realy is? for exemple: I have several objects that implement IEnumerable(these objects has arrayList), I need to Implement IEnumerator and I want to do it once. but I don't know for which object I implement it for so when I do : object.arrayList[i] -its an error. (object doen't have an arrayList property). how can I do it??? thanks in advance , sharon

      J Offline
      J Offline
      James T Johnson
      wrote on last edited by
      #2

      Ahhh, the beauty of programming via interfaces :) [contractual I think is the term]

      IEnumerable ie = myobject as IEnumerable

      if( ie != null )
      {
      // myobject implements IEnumerable so do something with it
      IEnumerator = ie.GetEnumerator();
      ...
      }

      HTH, James Simplicity Rules!

      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