【问题标题】:Cannot convert from "string" to "char" [duplicate]无法从“字符串”转换为“字符”[重复]
【发布时间】:2019-05-11 20:33:38
【问题描述】:

我看过类似的帖子,但找不到任何可以为我的案例提供答案的内容

string[] entries = File.ReadAllLines();
var orderedEntries = entries.OrderByDescending(x => int.Parse(x.Split(" ")[1]));
foreach (var entry in orderedEntries.Take(5))
{
    Console.WriteLine(entry);
}

错误似乎与这一行有关:

var orderedEntries = entries.OrderByDescending(x => int.Parse(x.Split(" ")[1]));

它说它不能从“字符串”转换为“字符”,我假设这意味着它只能由一个字符分割,有没有办法我可以改变它以允许我想要的空间,同时仍然保持它具有相同的功能。

*编辑,我不是有意将其作为副本,我什至不知道“分隔符”甚至是我的问题的一部分。很抱歉浪费您的时间。

【问题讨论】:

  • 改用x.Split(' ')

标签: c#


【解决方案1】:

改变这个

var orderedEntries = entries.OrderByDescending(x => int.Parse(x.Split(" ")[1]));

到这里

var orderedEntries = entries.OrderByDescending(x => int.Parse(x.Split(' ')[1]));

【讨论】:

    猜你喜欢
    • 2019-06-14
    • 1970-01-01
    • 2017-08-17
    • 2013-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-31
    • 2023-03-28
    相关资源
    最近更新 更多