0

I have a list of longs.For example:

List<long> myData = new List<long>{ 2 , 10, 12, 13}

I want to invoke ToString for this List and get a string with all list`s elements :

myData.ToString()

as a result "2,10,12,13" How can I do it? (Now when I run ToString() I got System.Collections.Generic.List1[System.Int64]`)

YAKOVM
  • 9,805
  • 31
  • 116
  • 217
  • If a class does not implement `ToString`, you get just that. Also, how is a `List` supposed to guess how you want that string (i.e. how to combine items)? – crashmstr Nov 24 '14 at 12:42

1 Answers1

1

You can use string.Join and LINQ select to achieve this, like so:

var dataAsString = string.Join(", ", myData.Select(s => s.ToString()));
Steve Lillis
  • 3,263
  • 5
  • 22
  • 41