码如下:
class Program
{
static void Main(string args)
{
SimpleClass simpleClass = new SimpleClass();
simpleClass.SecondField = "me";
string myString = simpleClass.OneField;
Console.WriteLine(myString);
Console.Read();
}
}
public class SimpleClass
{
private string _oneField = string.Empty;
private string _secondField = string.Empty;
public string OneField
{
get
{
if (_oneField.Length == 0)
{
_oneField = GetMyString();
}
return _oneField;
}
}
public string SecondField
{
get { return _secondField; }
set { _secondField = value; }
}
private string GetMyString()
{
return "SecondField:" + SecondField;
}
}以上这段代码正确的输出应该是:“SecondField:me”。
但如