C# convert array to list

In this post we will se how to convert array to list. We need to convert array object to generic list many times in C# programming. Converting array to list can be done by various ways. We are going to see C# examples to convert array to the list.

Conversion of array to an list can be done using constructor of the generic List class. We here use constructor of List and pass array object as parameter to List constructor and then convert it to List>

c# array to list
.

Example - convert array to list [C#]:

using System;
using System.Collections.Generic;

class Program
{
static void Main()
{
// String array to convert to list
 string[] strarr = new string[]
 {
  "Convert",
  "Array",
  "To",
  "list",
 };

//Now we will convert above array using new list constructor.
 List<string> arrayToList = new List<string>(strarr);
}

In above example we saw how we converted array to list using List constructor. Now we will see other way to convert Array to list. In this way we use .ToList() instance method that converts array to list. Below example shows how array get converted in to list using .ToList() parameter less instance method.

Example to convert array to list [C#]:

using System;
using System.Collections.Generic;

class Program
{    
static void Main()
{    
// String array to convert to list    
 string[] strarr = new string[]    
 {
  "Convert",
  "Array",
  "To",
  "List",
 };
//Now we will convert above array using .ToList instance method.
List<string> arrayToList = strarr.ToList();
}

24 comments :

  1. spot on with this write-up, i like the way you discuss the things. i'm impressed, i must say. i'll probably be back again to read more. thanks for sharing this with us.

    Lee Shin
    www.trendone.net

    ReplyDelete
  2. I definitely liked reading everything that is posted on your website.

    www.joeydavila.net

    ReplyDelete
  3. Awesome there, Great work, keep it up. I love returning back to this site and reading the quality content you always have on offer.

    kieth
    www.gofastek.com

    ReplyDelete

  4. When things get rough just stay calm and ask assistance from God and he'll give you peace. Visit my site for more information.

    triciajoy.com

    www.triciajoy.com

    ReplyDelete
  5. Love it! Very interesting topics, I hope the incoming comments and suggestion are equally positive. Thank you for sharing this information that is actually helpful.


    ufgop.org
    ufgop.org

    ReplyDelete
  6. I really enjoyed reading your article. I found this as an informative and interesting post, so i think it is very useful and knowledgeable. I would like to thank you for the effort you have made in writing this article.


    edupdf.org


    ReplyDelete
  7. Excellent post!!! The future of .net application development is on positive note. It offers huge career prospects for talented professionals all over the world. Training on .net technology will ensure good salary package. Best DOT NET Training in Chennai

    ReplyDelete
  8. Awesome there, Great work, keep it up. I love returning back to this site and reading the quality content you always have on offer.
    safety courses in chennai|Nebosh courses in chennai|IOSH courses in chennai|safety courses in Chennai|Diploma in safety courses training institute in chennai

    ReplyDelete
  9. I found this as an informative and interesting post, so i think it is very useful and knowledgeable. safety courses in chennai|Diploma in safety courses training institute in chennai

    ReplyDelete
  10. Every person has the passion in any aspects or things.
    If you love something and it came in front of you it completes your day and your mood turns into something you won't expected.
    I love your work and I want to read more about it. Visit my site if you have time . Thank you.

    triciajoy.com

    www.triciajoy.com

    ReplyDelete
  11. Greens Technology's. the leading software Training & placement centre Chennai & (Adyar)
    unix trainng in chennai

    ReplyDelete
  12. Greens Technology's. the leading software Training & placement centre Chennai & (Adyar)
    perl training in chennai

    ReplyDelete
  13. • Thank you for sharing this information and Very good looking blog.

    websphere training in chennai

    ReplyDelete
  14. Excellent post. I learned new concept, Thanks for sharing.

    digital marketing training in chennai

    ReplyDelete