当前位置:编程学习 > C#/ASP.NET >>

父子类 接口 问题

    /// <summary>
    /// 属性类
    /// </summary>
    public class A
    {
        private string name;
    }

    /// <summary>
    /// 属性子类
    /// </summary>
    public class B
    {
        private string age;
    }

    /// <summary>
    /// 接口
    /// </summary>
    public interface IGet
    {
        A GetValue();
    }

    /// <summary>
    /// 业务sql
    /// </summary>
    public class SQL : IGet
    {

        public A GetValue()
        {
            throw new NotImplementedException();
        }
    }
    /// <summary>
    /// 业务oracle
    /// </summary>
    public class Oracle : IGet
    {

        public B GetValue()
        {
            throw new NotImplementedException();
        }
    }



问题就是 Oracle 类的业务 应该返回 A的子类B 
代码 应该怎么写 有点混乱 类 接口 --------------------编程问答-------------------- 阿列- - --------------------编程问答-------------------- 啊定义 一个 IA 抽象类 然后 A,B继承自他就OK --------------------编程问答-------------------- public class Oracle :B, IGet
    {
 
        public B GetValue()
        {
            throw new NotImplementedException();
        }
    }
也可以继承类的不过类要放到所以接口前面! --------------------编程问答-------------------- class B : A

public interface IGet
{
    T GetValue<T>() where T : A;
} --------------------编程问答-------------------- 或者定义成泛型接口public interface IGet<T> where T : A
public class SQL : IGet<A>
public class Oracle : IGet<B>
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,