c# 继承 疑惑求解答。

异常异长 异常异长 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication4
{
class Program
{
public int a = 100;
public void min()
{
this.a--;
}
static void Main(string[] args)
{
test t = new test();
t.min();
Console.WriteLine(t.a);
Console.WriteLine(t.getA());
Console.Read();
}
}
class test : Program
{
int a = 8;
public void plus()
{
this.a++;
}
public int getA()
{
return base.a;
}
}
}

代码如上,我在调试时 t.min(); 中的 this.a-- this指向的是test 但是为什么this.a 却是使用的Program里的字段a 而不是test里的字段a。
...全文

相关推荐

评论 19
收藏 已收藏
分享
返回顶部
异常异长
C# 111,129 成员 642,540 内容