class ClassExamole
{
static void Main(string[] args)
{
//Console.Read();
Car car = new Car();
Console.WriteLine(car.DoSmothing());//输出 BMW
Console.Read();
}
}
class Car
{
private string name;//波浪线,提示已赋值,但其值从未使用过
public string DoSmothing()
{
return name = "BMW";
}
}
天蓬老师2017-04-17 17:39:36
The value of the field XXX is not used
因为你是用private进行声明的name变量表明是私有的,如果你不进行setter和getter方法的设置,其他类是无法对其进行设置和取值的。只要设置了就不会有波浪线了,可以用alt+shift+s快捷键进行代码生成。
ringa_lee2017-04-17 17:39:36
You can avoid errors by initializing it in the constructor or code block
PHP中文网2017-04-17 17:39:36
The foundation is flawed, my child, so I have never used it. If you don't believe me, it's easy to just return "BMW". The declared name is private and needs to be retrieved and assigned using the get and set methods. What is returned now is not the name. The basics, you must grasp the basics well.