C# MessageBox将显示什么?
我有下面这样的EventHandler代码 我不知道e.Value是什么意思,有人能解释一下MessageBox将显示什么吗C# MessageBox将显示什么?,c#,.net,enums,C#,.net,Enums,我有下面这样的EventHandler代码 我不知道e.Value是什么意思,有人能解释一下MessageBox将显示什么吗 void ConnectionManager_Error(object sender, EventArgs<string> e) { BeginInvoke((MethodInvoker)delegate() { State = ConnectState.NotFound;
void ConnectionManager_Error(object sender, EventArgs<string> e)
{
BeginInvoke((MethodInvoker)delegate()
{
State = ConnectState.NotFound;
MessageBox.Show(e.Value);
});
}
或
另一个提示
更具体地说,我还拥有以下代码:
public event EventHandler<EventArgs<string>> Error;
公共事件事件处理程序错误;
及
ConnectionManager.Error+=neweventhandler(ConnectionManager_Error);
还有这个班:
public class EventArgs<T> : EventArgs
{
public T Value
{
get;
set;
}
public EventArgs(T value)
: base()
{
Value = value;
}
}
公共类EventArgs:EventArgs
{
公共价值
{
得到;
设置
}
公共事件参数(T值)
:base()
{
价值=价值;
}
}
但即使设备未连接到计算机,MessageBox也不会出现。
我认为这是显示错误消息的消息框。
有人能告诉我出了什么问题吗?将显示一个消息框,其中包含EventArgs提供的值。我只能假设您的EventArgs类是一个泛型EventArgs实现,其中类型参数定义了值的类型
因此,无论值是什么,这都是您将在MessageBox中看到的。您的
ConnectionManager
具有Error
事件,它将EventArgs的实例传递给事件处理程序。我相信一般事件参数如下所示:
public class EventArgs<T> : EventArgs
{
public EventArgs(T value)
{
Value = value;
}
public T Value { get; private set; }
}
公共类EventArgs:EventArgs
{
公共事件参数(T值)
{
价值=价值;
}
公共T值{get;私有集;}
}
因此,ConnectionManager
为这个事件参数设置一些字符串值,并将其传递给ConnectionManager\u Error
事件处理程序。您应该看到传递的值。根据事件名称,我可以假设它应该是错误消息
注意:ConnectState
enum,ConnectionManager
的State
属性及其StateChanged
事件与您使用的代码无关。为什么不运行它并找出答案呢?因为当我执行整个解决方案时,即使设备未连接,消息框也不会出现在屏幕上。假定引发错误消息,显示发生的错误。
public event EventHandler<EventArgs<string>> Error;
ConnectionManager.Error += new EventHandler<EventArgs<string>>(ConnectionManager_Error);
public class EventArgs<T> : EventArgs
{
public T Value
{
get;
set;
}
public EventArgs(T value)
: base()
{
Value = value;
}
}
public class EventArgs<T> : EventArgs
{
public EventArgs(T value)
{
Value = value;
}
public T Value { get; private set; }
}