向现有类添加属性

时间:2011-01-17 17:59:28

标签: c#

我有一个现有的类,我想为它添加2个属性,not methods。这可能吗?如果不可能,我怎样才能继承它并拥有相同的类名?

3 个答案:

答案 0 :(得分:2)

public class MyBaseClass
{
public int Property1 { get; set; }
public int Property2 { get; set; }
}

public class MyDerivedClass : MyBaseClass
{
 public int Property3 { get; set; }
 public int Property4 { get; set; }
}

不能使用相同的名称继承,但是:

File1.cs

public partial class MyBaseClass
{
   public int Property1 { get; set; }
   public int Property2 { get; set; }
}

文件2。 CS

public partial class MyBaseClass
{
   public int Property3 { get; set; }
   public int Property4 { get; set; }
}

答案 1 :(得分:1)

没有扩展属性,你不能继承该类并使用相同的类名,除非你使用不同的命名空间,这可能不是你想要的。

答案 2 :(得分:0)

为什么不下载源代码(MVC3)并直接编辑该类?

相关问题