How do I convert a single char to a string?

后端 未结 11 1820
醉梦人生
醉梦人生 2020-12-18 17:24

I\'d like to enumerate a string and instead of it returning chars I\'d like to have the iterative variable be of type string. This pro

11条回答
  •  萌比男神i
    2020-12-18 18:10

    probably isn't possible to have the iterative type be a string

    Sure it is:

    foreach (string str in myString.Select(c => c.ToString())
    {
    ...
    }
    

    Any of the suggestions in the other answers can be substituted for c.ToString(). Probably the most efficient by a small hair is c => new string(c, 1), which is what char.ToString() probably does under the hood.

提交回复
热议问题