这段简单的c#代码为什么出错呢?

来源:百度知道 编辑:UC知道 时间:2024/06/02 14:36:37
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
test1 test1 = new test1();
Console.WriteLine(test1.say());
test1.color = "test";
Console.WriteLine(test1.color);
}

}
class test
{
public int MyInt;
public virtual string say()
{
return "Say!";
}

}
class test1 : test
{
public override string say()
{
return "SayX!";
}
public string color
{
get
{
return color;
}
set
{
color = va

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
test1 test1 = new test1();
Console.WriteLine(test1.say());
test1.color = "test";
Console.WriteLine(test1.color);
}

}

class test
{
public int MyInt;
public virtual string say()
{
return "Say!";
}

}

class test1 : test
{
public override string say()
{
return "SayX!";
}

private string _color;
public string color
{
get
{
return _color;
}

set
{
_color = value;
}
}
}
}

color在test1中没有对应的字段,属性应该依附与一个字段才可以。试试这个。

us