我需要一点帮助......我刚刚开始使用 C#,当布尔值发生变化时我需要引发一个事件。我有一堂课:
using System;
namespace WOCA
{
public class Arduino
{
public event EventHandler Disconnected;
**protected virtual void OnDisconnected()
{
EventHandler handler = Disconnected;
if (handler != null)
{
handler(this, EventArgs.Empty);
}
}**
private bool _isconnected;
public bool IsConnected
{
get
{
return _isconnected;
}
}
#region Methods
public void Connect()
{
//TODO implement code to connect
_isconnected = true;
}
public void Disconnect()
{
//TODO implement code to connect
_isconnected = false;
}
#endregion Methods
}
}
但是当 _isconnected 更改值时如何引发/触发事件?