【问题标题】:Trying to call from a .txt file and trying to use int.Parse but not working尝试从 .txt 文件调用并尝试使用 int.Parse 但不工作
【发布时间】:2020-06-22 14:48:49
【问题描述】:

【问题讨论】:

  • 把你的代码放进去而不是它的图像。这也是一个编译时错误。帮助我们帮助您...

标签: c# parsing int


【解决方案1】:

使用 int.Parse 创建 DateTime 对象的正确方法:

string year = "1994";
string month = "1";
string day = "14";
DateTime start = new DateTime(int.Parse(year), int.Parse(month), int.Parse(day));

【讨论】:

    【解决方案2】:

    让我们检查一下有问题的行:

    DateTime Start = int.Parse(readValues[3],
                                readValues[4],
                                readValues[5],
                                readValues[6],
                                readValues[7]);
    

    您将变量 Start 声明为 DateTime,但将其解析为 int。我的问题是:您在读取什么样的值,日期还是整数?

    除此之外,您正在向 int.Parse 传递几个参数,但无法判断您的意图是什么。

    我在这里有点冒险,但我认为该行应该是:

    DateTime Start = DateTime.Parse(readValues[3]);

    int Start = int.Parse(readValues[3]);

    【讨论】:

      猜你喜欢
      • 2017-12-10
      • 2016-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 2016-08-25
      相关资源
      最近更新 更多