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. assign values from 2d array into list<t>class</t>

assign values from 2d array into list<t>class</t>

Scheduled Pinned Locked Moved C#
csharpdata-structurestutorialquestion
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.
  • C Offline
    C Offline
    cst_kvp
    wrote on last edited by
    #1

    How to assign the values from two dimensional array into listclass in c#.net?

    S 1 Reply Last reply
    0
    • C cst_kvp

      How to assign the values from two dimensional array into listclass in c#.net?

      S Offline
      S Offline
      Simon P Stevens
      wrote on last edited by
      #2

      Loads of ways. 1) Do it yourself. Create a new list. Use a foreach loop. Loop through every item in the array and add it to the list. 2) Use .CopyTo to copy it to a single dimensional array, then all .ToList on the single dimensional array. 3) If you using .net 3.5, refernce the System.Linq assembly as use the Cast method: IEnumerable asList; asList = myArray.Cast();
      This give you an enumerable, which you can easily convert to a list if you want. The real question is why do you want a 2d array as a list? If you have data that is in 2 dimensions, why would you want to flatten it to 1 dimension. You can still use Foreach on a 2d array and loop over every element.

      Simon

      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