我正在嘗試學習編程,並從一本名爲Software Development Fundamentals的書開始。然而,我對於理解某些主題有困難。尤其是因爲我的母語不是英語。我被困在主題(事件)和(代表)。我覺得這對我來說很難,我甚至無法得到這個代碼的工作!C#該名稱在當前上下文中不存在
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Lesson02
{
class Program
{
static void Main(string[] args)
{
Rectangle r = new Rectangle();
r.Changed += new EventHandler(r_Changed);
r.Length = 10;
}
static void r_changed(object sender, EventArgs e)
{
Rectangle r = (Rectangle)sender;
Console.WriteLine(
"Value Changed: Length = {0}",
r.Length);
}
}
class Rectangle
{
public EventHandler Changed;
private double length;
public double Length
{
get
{
return length;
}
set
{
length = value;
Changed(this, EventArgs.Empty);
}
}
}
}
我得到這個錯誤:
Error 1 The name 'r_Changed' does not exist in the current context 14 59 Lesson02
C#是區分大小寫的。檢查「r_Changed」與「r_changed」的拼寫 – David