[英]cannot convert from 'System.Collections.Generic.IEnumerable<char>' to 'string'
I try to Reverse my string but I get to following error 我试图反转我的字符串,但我得到跟随错误
string str = word.Reverse();
error: 错误:
cannot convert from 'System.Collections.Generic.IEnumerable' to 'string'
无法从'System.Collections.Generic.IEnumerable'转换为'string'
anyone know what should I need to do ? 有谁知道我该怎么办?
You should build a new string. 你应该建立一个新的字符串。
string str = new string(word.Reverse().ToArray());
Calling ToArray()
on an IEnumerable<T>
will convert it to T[]
. 在
IEnumerable<T>
上调用ToArray()
会将其转换为T[]
。
string
has a constructor which get array of character and constructs a string. string
有一个构造函数,它获取字符数组并构造一个字符串。
您应该将字符连接在一起以创建新字符串。
string str = string.Join(string.Empty, word.Reverse());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.