c# - 将部分类与普通类相结合

标签 c# partial-classes

是否可以像这样将普通类与部分类结合起来:

public class ClassA
{
    public string PropertyA {get; set;}
}

public partial class ClassA
{
    public string PropertyB {get; set;}
}

代码的结果应该是:

var instance = new ClassA();

instance.PropertyA = "Something";
instance.PropertyB = "Something else";

C# 支持这种模式吗?

提前谢谢大家!

最佳答案

简短回答: MSDN 声明here :

All the parts must use the partial keyword. All of the parts must be available at compile time to form the final type. All the parts must have the same accessibility, such as public, private, and so on.

关于c# - 将部分类与普通类相结合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10991214/

相关文章:

c# - 自动登录到我们自己的 OAuth 应用程序

c# - 使用 Result 时出现死锁

c# - 动态填充数据网格

c# - 使自动生成的部分类实现自定义接口(interface)

c# - 部分类和访问修饰符问题

c# - LINQ to SQL - 使用部分类和方法扩展数据上下文时出现编译错误

c# - 对部分类/方法的 XML 注释

c# - 从 javascript 到 C# 的日期不起作用

c# - LINQ-to-SQL 中的多个 where 子句和 && 运算符有什么区别?

c# - 在泛型类上使用 "partial"