Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#:无法隐式转换类型';System.Collections.Generic.List<;char>';至';System.Collections.Generic.List<;字符串>';_C#_List_Type Conversion - Fatal编程技术网

C#:无法隐式转换类型';System.Collections.Generic.List<;char>';至';System.Collections.Generic.List<;字符串>';

C#:无法隐式转换类型';System.Collections.Generic.List<;char>';至';System.Collections.Generic.List<;字符串>';,c#,list,type-conversion,C#,List,Type Conversion,我想做一些控制台框架,为此我需要命令和命令参数。以下是我的部分代码: string str = "I do not know how to fix this problem"; List<string> substringList = str.Split().ToList(); List<string> allArgsExcept1st = str[1..^0].ToList(); string str=“我不知道如何解决这个问题”; List substringLis

我想做一些控制台框架,为此我需要命令和命令参数。以下是我的部分代码:

string str = "I do not know how to fix this problem";
List<string> substringList = str.Split().ToList();
List<string> allArgsExcept1st = str[1..^0].ToList();
string str=“我不知道如何解决这个问题”;
List substringList=str.Split().ToList();
列出allArgsExcept1st=str[1..^0].ToList();
输入类型为
string
。 第三行抛出一个错误:

无法将类型“System.Collections.Generic.List”隐式转换为“System.Collections.Generic.List”

我是C#的新手,所以我不知道该如何看待这个错误,以及如何可能地修复它


谢谢。

根据您最近的编辑:

string str = "I do not know how to fix this problem";
List<string> substringList = str.Split().ToList();
List<string> allArgsExcept1st = str[1..^0].ToList();
当您在
字符串上使用范围/切片功能(
[1..^0]
)时,您将得到一个
字符串。因此,在该
字符串上调用
ToList()
将为您提供一个
列表
(因为
字符串
也是一个
IEnumerable
),但您正在将其分配给
列表

现在还不清楚您最终要做什么,但要解决问题,您只需将最后一行更改为:

List<char> allArgsExcept1st = str[1..^0].ToList();
List allArgsExcept1st=str[1..^0].ToList();

@Maddy这个答案还不是很有用。缺少重要的上下文,可能会改变答案是否正确relevant@maccettura,完全同意,但如果用户发现其信息足够,请立即停止!我只是不想过早地将其标记为dupe,你的意思是
var allArgsExcept1st=substringList.Skip(1)?你为什么要把所有东西都转换成一个
列表
?我没有否决投票,但我怀疑这掩盖了错误,而不是纠正错误。@DourHighArch是的,我可以看到。我借此机会向OP教授字符串的IEnumerable,了解其切片代码的含义。OP没有给出太多细节,所以在他们提供反馈之前,我无法提供更好的反馈。然而,我仍然认为我的答案实际上是正确的,OP的问题在技术上仍然符合idk的标准
List<char> allArgsExcept1st = str[1..^0].ToList();