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. How to copy ICollection object contents to List ?

How to copy ICollection object contents to List ?

Scheduled Pinned Locked Moved C#
tutorialquestion
5 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.
  • K Offline
    K Offline
    kumar bs
    wrote on last edited by
    #1

    I have method to which object of Type ICollection is getting passed. I want to create an object of List<> (Generic List) , with object of ICollection. Is that possible? kumar

    C 1 Reply Last reply
    0
    • K kumar bs

      I have method to which object of Type ICollection is getting passed. I want to create an object of List<> (Generic List) , with object of ICollection. Is that possible? kumar

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You can use the ICollection interface to iterate over the collection, and then put the items into a List, or whatever.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      K 1 Reply Last reply
      0
      • C Christian Graus

        You can use the ICollection interface to iterate over the collection, and then put the items into a List, or whatever.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        K Offline
        K Offline
        kumar bs
        wrote on last edited by
        #3

        thanks, but i don't want to iterate, is that direct way, like while creating ArrayList object we can directly pass ICollection object to the constructor of ArrayList so that the contents of ICollection get copied to Arraylist object, is something like possible with generic List (List<>) object?

        C 1 Reply Last reply
        0
        • K kumar bs

          thanks, but i don't want to iterate, is that direct way, like while creating ArrayList object we can directly pass ICollection object to the constructor of ArrayList so that the contents of ICollection get copied to Arraylist object, is something like possible with generic List (List<>) object?

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          I don't think so, not if the ICollection is not templated. because, the difference is, an ArrayList and an ICollection both knew they were just holding objects.

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

          K 1 Reply Last reply
          0
          • C Christian Graus

            I don't think so, not if the ICollection is not templated. because, the difference is, an ArrayList and an ICollection both knew they were just holding objects.

            Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

            K Offline
            K Offline
            kumar bs
            wrote on last edited by
            #5

            Thanks Graus

            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