开发者

How to join Queue(Of String) as a string?

I have following code:

Dim PendingFiles As New Queue(Of String)

I need to join each element of PendingFiles with a comma and store the result as a string. How do I achieve it?

Something like this:

Dim Result As String
Result = Join(PendingFiles, ",")
'NOTE: this the way if PendingFiles is a string array. 
'      But now, it is Queue(Of String)开发者_如何转开发. So how do I join it?


Use the String.Join<T>(string separator, IEnumerable<T> values) method:

Result = String.Join(",", PendingFiles);


If you are using .NET 2.0 then @jason solution won't work.

Try this instead:

Result = String.Join(",", PendingFiles.ToArray());

Why would you use .NET 2.0 ? One example is for API compatibility in Unity3D.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜