/// <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;
不进行实例化,是A.str而不是a.str
是A.str不实例化就引用的。。 不符合要求啊。
越写越觉得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;
/// <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;
不符合要求啊。
///
/// </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;
当然,要是哪位兄弟有其他的想法可以email我[email protected]。
谢谢。