The way you have written it DateOfHire
is not a method, it is a property.
(您编写DateOfHire
方式不是方法,而是属性。)
The property is trying to act on a local member variable called dateOfHire
which does not exist in scope. (该属性正在尝试对作用dateOfHire
不存在的名为dateOfHire
的局部成员变量dateOfHire
。)
So, no wonder you are getting an error. (因此,难怪您遇到错误。)
Try changing DateOfHire
to a proper method.
(尝试将DateOfHire
更改为适当的方法。)
You will need to pass your local value of dateOfHire
(obtained from Parse()
) into the method using a parameter. (您将需要使用参数将dateOfHire
的本地值(从Parse()
)传递到方法中。)
public void DateOfHire(DateTime dateOfHire)
{
Console.WriteLine(dateOfHire.ToString("D"));
}
Also, DateOfHire
cannot have a return type of DateTime
like your property defines.
(另外, DateOfHire
不能具有属性定义的DateTime
返回类型。)
This is because you aren't returning anything, you are simply writing the result to the console. (这是因为您什么都不返回,只是将结果写入控制台。)
So for your method, the void
return type is implied. (因此,对于你的方法,将void
返回类型是隐含的。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…