【发布时间】:2012-06-21 10:36:35
【问题描述】:
我在网上搜索但在定义部分类时没有找到有关约束/规则的任何有用信息,我的意思是所有类都可以命名为 Partial 还是某些类不能命名?静态类可以是部分的,所有这些东西,请解释清楚 我在面试中被问到这个问题,我没有任何答案。我真的很想深入了解这一点,我曾经在 msdn 中找到了一些用于定义部分方法的规则,例如
1. Partial method declarations must begin with the contextual keyword
2. partial and the method must return void.
3. Partial methods can have ref but not out parameters.
4. Partial methods are implicitly private, and therefore they cannot be virtual.
5. Partial methods cannot be extern , because the presence of the body determines whether they are defining or implementing.
6. Partial methods can have static and unsafe modifiers.
7. Partial methods can be generic.
8. Constraints are put on the defining partial method declaration, and
may optionally be repeated on the implementing one.
9. Parameter and type parameter names do not have to be the same in the
implementing declaration as in the defining one.
10. You can make a delegate to a partial method that has been defined and implemented, but not to a partial method that has only been defined.
类也有规则吗...
感谢小伙伴们
【问题讨论】:
-
伙计们,请看我询问部分课程的约束/规则。我知道部分课程的用途......例如。我们可以将部分添加到静态类中吗...在哪些方面我不能将类声明为部分..
标签: c# partial-classes