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";
}
}
The name field is indeed not used. . .
You can avoid errors by initializing it in the constructor or code block
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.