日期:2014-05-18  浏览次数:21056 次

EventArgs 参数赋值问题

EventArgs e = new EventArgs();

请问如何给上面的e赋值,如e="abc"这样

------解决方案--------------------
想什么呢,那能赋值吗,类型都不对付
------解决方案--------------------
http://msdn.microsoft.com/zh-cn/library/system.eventargs(v=vs.80).aspx

c#要有类型的概念,e是EventArgs类型,"abc"是string类型,不能这么干的
------解决方案--------------------
假如你想给 ...(.., EventArgs e) 这种方法传递多些的参数,可以定义个类型继承 EventArgs 
C# code
public class EventArgsEx : EventArgs
{
    public string str;
}

// 创建
EventArgsEx e = new EventArgsEx();
e.str = "abc";

// 调用方法 
...(..., e);

...(.., EventArgs e)
{
   // 取出
   EventArgsEx ex = (EventArgsEx)e;
   ... = ex.str;
}