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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Converting Array int[] to List

Converting Array int[] to List

Scheduled Pinned Locked Moved C#
data-structurestutorialquestion
5 Posts 3 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
    srivatsan24
    wrote on last edited by
    #1

    Can anyone tell me how to covert an array int[] into List I do not want to use a for loop to traverse through the array and add the elements to the list. Is there something like toArray which converts list to array? Srivatsan

    T J 2 Replies Last reply
    0
    • S srivatsan24

      Can anyone tell me how to covert an array int[] into List I do not want to use a for loop to traverse through the array and add the elements to the list. Is there something like toArray which converts list to array? Srivatsan

      T Offline
      T Offline
      tgrt
      wrote on last edited by
      #2

      I'm not sure if you're talking about an ArrayList or a List. Both have AddRange methods which should take your array just fine. Both also have ToArray methods.

      1 Reply Last reply
      0
      • S srivatsan24

        Can anyone tell me how to covert an array int[] into List I do not want to use a for loop to traverse through the array and add the elements to the list. Is there something like toArray which converts list to array? Srivatsan

        J Offline
        J Offline
        Judah Gabriel Himango
        wrote on last edited by
        #3

        int[] items = { 5, 10, 15 };
        List<int> list = new List<(items);

        Tech, life, family, faith: Give me a visit. I'm currently blogging about: The Lord's Prayer in Aramaic song (audio) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

        S 2 Replies Last reply
        0
        • J Judah Gabriel Himango

          int[] items = { 5, 10, 15 };
          List<int> list = new List<(items);

          Tech, life, family, faith: Give me a visit. I'm currently blogging about: The Lord's Prayer in Aramaic song (audio) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

          S Offline
          S Offline
          srivatsan24
          wrote on last edited by
          #4

          Hey thanks for the reply. I will try it out. I am already home. Thanks. I will get reply back as soon as i try it out.

          1 Reply Last reply
          0
          • J Judah Gabriel Himango

            int[] items = { 5, 10, 15 };
            List<int> list = new List<(items);

            Tech, life, family, faith: Give me a visit. I'm currently blogging about: The Lord's Prayer in Aramaic song (audio) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

            S Offline
            S Offline
            srivatsan24
            wrote on last edited by
            #5

            Hey thanks for the idea. The code which works is as below int[] items = { 5, 10, 15 }; List<int> list = new List<int>(items); Srivatsan

            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