栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > .Net

问题解决:System.FormatException:“Input string was not in a correct format.”

.Net 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

问题解决:System.FormatException:“Input string was not in a correct format.”

问题:
    double days = 107653 / 86400;
    Console.WriteLine(days);
    double hours = (107653 % 86400) / 3600;
    Console.WriteLine(hours);
    double minutes = ((107653 % 86400) % 3600) / 60;
    Console.WriteLine(minutes);
    double seconds = (((107653 % 86400) % 3600) % 60) / 60;
    Console.WriteLine(seconds);
    Console.WriteLine("107653是{}天{}小时{}分钟{}秒", days,hours,minutes,seconds);
    Console.ReadKey();
执行这个程序出现错误,
System.FormatException
  HResult=0x80131537
  Message=Input string was not in a correct format.
  Source=System.Private.CoreLib
  StackTrace:
   at System.Text.StringBuilder.FormatError()
   at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)
   at System.IO.StreamWriter.WriteFormatHelper(String format, ParamsArray args, Boolean appendNewLine)
   at System.IO.StreamWriter.WriteLine(String format, Object[] arg)
   at System.IO.TextWriter.SyncTextWriter.WriteLine(String format, Object[] arg)
   at System.Console.WriteLine(String format, Object[] arg)
   at Learing.Program.Main(String[] args) in E:C#DateLearnLearingProgram.cs:line 38
原因: 在大括号{}里没有添加序号导致的 解决: 应该在输出的{}里分别加入序号{0}{1}…。 更改后:
    double days = 107653 / 86400;
    Console.WriteLine(days);
    double hours = (107653 % 86400) / 3600;
    Console.WriteLine(hours);
    double minutes = ((107653 % 86400) % 3600) / 60;
    Console.WriteLine(minutes);
    double seconds = (((107653 % 86400) % 3600) % 60) / 60;
    Console.WriteLine(seconds);
    Console.WriteLine("107653是{1}天{2}小时{3}分钟{4}秒", days,hours,minutes,seconds);
    Console.ReadKey();
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/903915.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号