A是父类,B,C都是子类
str是string变量
如何让A.str + B.str + C.str + A.str + B.str的结果为ABCAB

解决方案 »

  1.   


    /// <summary>
        /// 
        /// </summary>
        public class A
        {
            /// <summary>
            /// 
            /// </summary>
            private string m_str = null;        public string STR
            {
                get
                {
                    return this.m_str;
                }
                set
                {
                    this.m_str = value;
                }
            }        public A()
            {
                this.m_str = this.GetType().Name;
            }
        }    /// <summary>
        /// 
        /// </summary>
        public class B : A
        {
            public B()
            {
                this.STR = this.GetType().Name;
            }
        }    /// <summary>
        /// 
        /// </summary>
        public class C : A
        {
            public C()
            {
                this.STR = this.GetType().Name;
            }
        }A a = new A();
                B b = new B();
                C c = new C();
                // strs输出ABCAB
                string strs = a.STR + b.STR + c.STR + a.STR + b.STR;
      

  2.   

    不进行实例化,是A.str而不是a.str
      

  3.   

    是A.str不实例化就引用的。。
    不符合要求啊。
      

  4.   

    越写越觉得BT了。。/// <summary>
        /// 
        /// </summary>
        public class A
        {
            /// <summary>
            /// 
            /// </summary>
            public static string m_str = System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name;
           
        }    /// <summary>
        /// 
        /// </summary>
        public class B : A
        {        
            public static string m_str = System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name;        
        }    /// <summary>
        /// 
        /// </summary>
        public class C : A
        {
            public static string m_str = System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name;       
        }输出ABCABstring strs = A.m_str + B.m_str + C.m_str + A.m_str + B.m_str;
      

  5.   

    joe兄弟有个问题你一开始就找错了方向,我说的ABCAB其实是和类名完全无关的东西。他也可以是abcab或者12312或者a1b2c3a1b2之类的,在我的设想中这是后来附的。不过没关系了,难得有这么热心的网友,再次感谢。
    当然,要是哪位兄弟有其他的想法可以email我[email protected]
    谢谢。