C# 在C语言中从多个类继承#

C# 在C语言中从多个类继承#,c#,inheritance,C#,Inheritance,我有一个类Annotations,以及从中继承的两个类HousingAnnotations和AutoAnnotations public class Annotations { public string original_posting_date { get; set; } public string price { get; set; } } public class HousingAnnotations : Annotations { public stri

我有一个类Annotations,以及从中继承的两个类HousingAnnotations和AutoAnnotations

 public class Annotations
{
    public string original_posting_date { get; set; }
    public string price { get; set; }

}

public class HousingAnnotations : Annotations
{

    public string laundry_on_site { get; set; }
    public string condo { get; set; }
    public string w_d_in_unit { get; set; }
    public string street_parking { get; set; }
    public string w_d_hookups { get; set; }
    public string bedrooms { get; set; }

}

public class AutoAnnotations : Annotations
{
    public string vin { get; set; }
    public string year { get; set; }
}
例如,我想做的是允许填充Auto或HousingAnnotation,而不指定哪种类型

AnnotationHelper annotation = new AnnotationHelper{bedrooms = "2", vin = "123"};

或者类似的。既然我不能同时从这两个类继承,我该如何解决这个问题呢?我知道存在使用接口的变通方法,但我不希望必须调用AnnotationHelper类中的每个属性。有什么方法可以解决这个问题?

如果你打算这样使用它们,你需要单独的类有什么原因吗?可能是@Blorgbeard的重复我计划将其用作输入/输出类,这样我可以有时区分(给cient不同的类分组),但也可以将它们组合起来(当基于这些属性值获取数据时,所有数据都是内联的,没有真正的区别)根据我上面的评论,你只是用它来传递类作为一个整体。为什么不创建一个以类作为字段的结构并传递呢?“我计划将它用作一个输入/输出类,以便有时能够区分”——听起来像是一个完美的接口用例。或者,只需使用composition并让该类公开两个不同类的包含实例。