简体   繁体   English

无法从&#39;System.Collections.Generic.IEnumerable转换 <char> &#39;到&#39;字符串&#39;

[英]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.

相关问题 TreeView:无法从&#39;System.Collections.Generic.IEnumerable转换 <string> &#39;到&#39;System.Collections.Generic.IEnumerable - TreeView: Cannot convert from 'System.Collections.Generic.IEnumerable<string>' to 'System.Collections.Generic.IEnumerable 无法从&#39;System.Collections.Generic.IEnumerable转换为System.Collections.Generic.IEnumerable <string> - Cannot convert from 'System.Collections.Generic.IEnumerable to System.Collections.Generic.IEnumerable<string> 无法从“ System.Collections.Generic.IEnumerable”转换为System.Collections.Generic.IEnumerable <string> - cannot convert from 'System.Collections.Generic.IEnumerable' to System.Collections.Generic.IEnumerable<string> 无法从&#39;System.Collections.Generic.IEnumerable转换 <System.Collection.Generic.List<char> &gt;字符串[] - Cannot convert from 'System.Collections.Generic.IEnumerable<System.Collection.Generic.List<char>> to string[] 无法从“System.Collections.Generic.IEnumerable”转换<string> &#39; 到 &#39;T&#39; - cannot convert from 'System.Collections.Generic.IEnumerable<string>' to 'T' 无法从&#39;System.Collections.Generic.IEnumerable转换 <int> &#39;到&#39;System.Collections.Generic.IEnumerable <int?> “ - Cannot convert from 'System.Collections.Generic.IEnumerable<int>' to 'System.Collections.Generic.IEnumerable<int?>' 无法隐式转换类型&#39;System.Collections.Generic.IEnumerable <char> “ to”字符串 - Cannot implicit convert type 'System.Collections.Generic.IEnumerable<char>'to'string CS0266 无法隐式转换类型 'System.Collections.Generic.IEnumerable<char> '到'字符串'</char> - CS0266 cannot implicitly convert type 'System.Collections.Generic.IEnumerable<char>' to 'string' 从&#39;string&#39;转换为&#39;System.Collections.Generic.IEnumerable <string> - Convert from 'string' to 'System.Collections.Generic.IEnumerable<string> Linq无法从&#39;System.Collections.Generic.IEnumerable转换 <string> &#39;to&#39;string []&#39; - Linq cannot convert from 'System.Collections.Generic.IEnumerable<string>' to 'string[]'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM