Max*_*Max 3 c# communication params
我正在开发一个简单的API,它将接受许多IBehaviours,然后在配置中应用它们.我使用params关键字设计它,因为通常只需要一个行为,但有时更多.
但是,以正确的顺序应用行为非常重要.
public void Configure(string wow, params IBehaviour[] behaviours) { ... }
Configure("oh yes", new MustHappenFirst(), new MustHappenSecondly());
Run Code Online (Sandbox Code Playgroud)
做这个
技术上暗示behaviours
在枚举时以相同的顺序发生?(在标准方面,不仅仅是实际上).
在语义上和直觉上传达相同的行为?
谢谢.
参数的评估将按从左到右的顺序进行,并且它们将按顺序放入数组中.
请注意,如果"null"是行为的有效值,则可能会遇到麻烦:
Configure("hello", null);
Run Code Online (Sandbox Code Playgroud)
电话
Configure("hello", (IBehaviour[]) null);
Run Code Online (Sandbox Code Playgroud)
不
Configure("hello", new IBehaviour[1] { null } );
Run Code Online (Sandbox Code Playgroud)
所以要小心.