动作<> VS事件行动 [英] Action<> Vs event Action
问题描述
是
public event Action delt = () => { Console.WriteLine("Information"); };
an overloaded version of
Action<int, int> delg = (a, b) => { Console.WriteLine( a + b); }; ?
我的意思是动作<?>委托是事件行动的重载版本
I mean Action<> delegate is an overloaded version of "event Action"?
推荐答案
这不是所谓的过剩。
基本上,有一组类型,声明如下:
Basically, there is a set of types, declared like this:
namespace System {
delegate void Action();
delegate void Action<T>(T a);
delegate void Action<T1, T2>(T1 a1, T2 a2);
...
}
每个人是不同类型的,独立的所有其他。编译器知道你说的是哪类型当您尝试通过<的存在与否来引用它;>
类型名称后,和类型参数中的数字<>
Each of them is a different type, independent of all other. The compiler knows which type you mean when you try to reference it by the presence or absence of <>
after the type name, and the number of type parameters within <>
.
事件
是一个完全不同的事情。 ,且不在此发挥任何部分。如果你按事件和委托之间的区别感到困惑,看到这两个问题:的 1 2
event
is a different thing altogether, and doesn't play any part in this. If you're confused by the difference between event and delegate, see these two questions: 1 2
这篇关于动作<> VS事件行动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!