Reputation: 2085
I'm trying to go something really simple here and apparently not possible. I have a datetime array
DateTime[] dtArray = new DateTime[50];
This has few dates. I need to convert this datetime array to a string to be able to store in ApplicationDataContainer.
string test = dtArray.ToString();
This gives me text DateTime[].. Is there no direct way to convert the whole array to string or do I have to use for loop and convert each in to string and concatenate it?
Upvotes: 0
Views: 4804
Reputation: 23087
You need to use String.Join and Select
string format = "yyyy-MM-dd";
string test = string.Join(",",dtArray.Select(x=>x.ToString(format)));
above you can use custom format
Or shorter (without format)
string test = string.Join(",",dtArray);
Upvotes: 8