在我的C#代码中,我有一个包含属性和函数的类。现在,我想让我的函数GetCar返回具有值的类类型的对象。如何从C#中的类self返回类的对象?
我在我的代码中有错误,但找不到它。
public class Car
{
public int CarHouseID { set; get; }
public int CarsInHouse{ set; get; }
public int CarSold { set; get; }
public Car GetCar()
{
return Car;
}
}
这不是很明智的代码。而不是obj.GetCar(),你只需使用obj。 –
你想调用构造函数吗?例如'汽车=新车();'。 –
所以你有一个_Car实例= new Car()_并且你想调用_Car newInstance = instance.GetCar(); _这没什么意义。 – Steve