Tag: 派生

C#:为派生类inheritance单独的静态成员

我的问题简要说明: class A { /* Other stuff in my class*/ protected static staticMember; } class B : A { /* Other stuff in my class*/ // Will have A.staticMember but I want B.staticMember (same type) } class C : A { /* Other stuff in my class*/ // Will have A.staticMember but I want C.staticMember […]

访问派生类中的基类变量

class Program { static void Main(string[] args) { baseClass obj = new baseClass(); obj.intF = 5; obj.intS = 4; child obj1 = new child(); Console.WriteLine(Convert.ToString(obj.addNo())); Console.WriteLine(Convert.ToString(obj1.add())); Console.ReadLine(); } } public class baseClass { public int intF = 0, intS = 0; public int addNo() { int intReturn = 0; intReturn = intF + intS; return […]

基类与实用类

应该首选哪两个? 有一些方法被A,B和C类调用。 这些方法是否应该封装在D类(A,B和C的基础)中? 要么 如果这些方法被封装在类U和其他类创建中,则它的对象是根据需要使用这些方法。 在什么基础上应该做出决定? 谢谢。

从C#中的Entity Framework生成的类派生

我创建了一个实体数据模型并从中生成了一个数据库。 其中一个实体称为Template 。 创建部分类以扩展Template的function可以正常工作。 如果我创建一个新类并尝试从Template派生,我会在实例化时遇到运行时exception: Mapping and metadata information could not be found for EntityType ‘Template001’ 。 我该如何解决这个问题? 我肯定需要inheritanceEF类。 编辑 似乎不可能。 如果是这种情况,那么实现以下要求的最佳方法是:模板实体存储有关每个都有自己的代码要执行的模板的信息。 这就是为什么我试图从实体派生出来的原因。

C#派生类的XML序列化

您好我正在尝试序列化从类派生的对象数组,我使用c#继续遇到相同的错误。 任何帮助深表感谢。 很明显,这个例子已经按照现实世界中这篇文章的目的缩小了。形状将包含大量不同的形状。 Program.cs中 namespace XMLInheritTests { class Program { static void Main(string[] args) { Shape[] a = new Shape[1] { new Square(1) }; FileStream fS = new FileStream(“C:\\shape.xml”, FileMode.OpenOrCreate); XmlSerializer xS = new XmlSerializer(a.GetType()); Console.WriteLine(“writing”); try { xS.Serialize(fS, a); } catch (Exception e) { Console.WriteLine(e.InnerException.ToString()); Console.ReadKey(); } fS.Close(); Console.WriteLine(“Fin”); } } } Shape.cs namespace […]