:System.FormatException中的WriteLine
System.FormatException
其他信息:輸入字符串的不正確的格式。
我在我的Visual Studio C#解決兩個文件:
的Program.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;
當我使用分步執行(F10
)
極少數情況下'FormatException'不
{
和0
之間的空間由於'int.Parse(「bob」)'... –