大家过来看看,一个很简单的问题

cbenny 2003-08-23 04:16:38
程序如下,很简单
using System;
class MyClass
{protected string mystring;
public string ContainedString
{
set
{
mystring = value;
}
}
virtual public string GetString()
{return mystring;}
}
class MyDerivedClass : MyClass
{
public override string GetString(){
string st;
st = ((MyClass)this).GetString();
st+="haha";
return st;
}
public static void Main()
{
MyDerivedClass a;
a = new MyDerivedClass();
((MyClass)a).ContainedString ="hello world";
string st;
st = a.GetString();
Console.WriteLine("the value of a is :{0}",st);
}
}
编译通过了阿,可是执行的时候他会溢出,郁闷,
还请大虾指点阿
...全文
16 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
qqq123 2003-08-23
  • 打赏
  • 举报
回复
st = ((MyClass)this).GetString();
改为:
st = base.GetString();
cbenny 2003-08-23
  • 打赏
  • 举报
回复
st = ((MyClass)this).GetString();
我单步跟踪的时候,发现他执行到这一句,就走不了了,一直执行这句,这是为啥阿

110,502

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧