How do I convert a single char to a string?

后端 未结 11 1798
醉梦人生
醉梦人生 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条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-18 18:03

    You have two options. Create a string object or call ToString method.

    String cString = c.ToString();
    String cString2 = new String(c, 1); // second parameter indicates
                                        // how many times it should be repeated
    

提交回复
热议问题