Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 订阅一个类的多个实例的事件_C#_Algorithm_Events - Fatal编程技术网

C# 订阅一个类的多个实例的事件

C# 订阅一个类的多个实例的事件,c#,algorithm,events,C#,Algorithm,Events,我有一个自定义形状类的程序,如下所示 class Shape { public: Event<ShapeArgs> shapeBurst; virtual void onMousePress(); //inside this, shapeBurst event is notifed }; 如果您有15个形状对象,则可以使用对象数组而不是15个变量,并使用循环订阅事件 for(int i=0; i < shape.Length;i++) shape[i].shapeBurs

我有一个自定义形状类的程序,如下所示

class Shape
{
public:
Event<ShapeArgs> shapeBurst;
virtual void onMousePress(); //inside this, shapeBurst event is notifed
};

如果您有15个形状对象,则可以使用对象数组而不是15个变量,并使用循环订阅事件

for(int i=0; i < shape.Length;i++)
  shape[i].shapeBurst += new ShapeBurstEventHandler(ShapeBurstMethod);
for(int i=0;i
for(int i=0; i < shape.Length;i++)
  shape[i].shapeBurst += new ShapeBurstEventHandler(ShapeBurstMethod);