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);