【发布时间】:2015-10-16 03:47:08
【问题描述】:
我的代码遇到了这个异常:
System.FormatException
附加信息:输入字符串的格式不正确。
我的 Visual Studio C# 解决方案中有两个文件:
-
程序.cs:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace EventPubSub { class Program { static void Main(string[] args) { Rectangle rect = new Rectangle(); // Subscribe to the Changed event rect.Changed += new EventHandler(Rectangle_Changed); rect.Length = 10; } static void Rectangle_Changed(object sender, EventArgs e) { Rectangle rect = (Rectangle)sender; Console.WriteLine("Value Changed: Length = { 0}", rect.Length); } } } -
文件
Rectangle.cs:using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace EventPubSub { class Rectangle { //Declare an event named Changed of //delegate type EventHandler public event EventHandler Changed; private double length = 5; public double Length { get { return length; } set { length = value; //Publish the Changed event Changed(this, EventArgs.Empty); } } } }
执行该行时出现异常:rect.Length = 10;
【问题讨论】:
-
FormatException不是由于int.Parse("bob")引起的罕见情况...
标签: c# console.writeline formatexception