gpt4 book ai didi

c# - 无法从 'System.Collections.Generic.IEnumerable' 转换为 'string'

转载 作者:行者123 更新时间:2023-11-30 13:21:53 26 4
gpt4 key购买 nike

我尝试反转我的字符串,但出现以下错误

string str = word.Reverse();

错误:

cannot convert from 'System.Collections.Generic.IEnumerable' to 'string'

有人知道我需要做什么吗?

最佳答案

你应该建立一个新的字符串。

string str = new string(word.Reverse().ToArray());

调用 ToArray()IEnumerable<T> 上会将其转换为 T[] .

string有一个构造函数,它获取字符数组并构造一个字符串。

关于c# - 无法从 'System.Collections.Generic.IEnumerable<char>' 转换为 'string',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34551724/

26 4 0