using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace Chapter3HomeWork1
{
class Car
{
private string _name;
public string Name
{
get { return _name; }
set { _name = "奔驰"; }
} private string _color;
public string Color
{
get { return _color; }
set { _color = "蓝颜色";}
} private string _productPlace;
public string ProductPlace
{
get { return _productPlace; }
set { _productPlace = "德国"; }
} public void Run()
{
Console.WriteLine("我是一辆{0}车,{1},产地是{2}",Name,Color,ProductPlace);
}
}
}using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace Chapter3HomeWork1
{
class Program
{
static void Main(string[] args)
{
Car car = new Car();
car.Run();
}
}
}名字和产地都显示没有显示颜色怎么回事。刚学属性不是很了解还请帮助
void Main()
{
Car car = new Car();
car.Run();
//我是一辆奔驰车,蓝颜色,产地是德国
}
class Car
{
private string _name= "奔驰";
public string Name
{
get { return _name; }
set { _name = value; }
} private string _color = "蓝颜色";
public string Color
{
get { return _color; }
set { _color = value;}
} private string _productPlace= "德国";
public string ProductPlace
{
get { return _productPlace; }
set { _productPlace =value; }
} public void Run()
{
Console.WriteLine("我是一辆{0}车,{1},产地是{2}",Name,Color,ProductPlace);
}
}
car.ProductPlace="231";
car.Run();
class Car
{
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
} private string _color;
public string Color
{
get { return _color; }
set { _color = value;}
} private string _productPlace;
public string ProductPlace
{
get { return _productPlace; }
set { _productPlace = value; }
} public void Run()
{
Console.WriteLine("我是一辆{0}车,{1},产地是{2}",_name,_color,_productPlace);
}
}
public static void Main(string[] args)
{
Car car = new Car();
car.Name = "奔驰";
car.Color = "蓝颜色";
car.ProductPlace = "德国";
car.Run();
Console.Read();
}
public void Run()
{
Name = "123";
Color = "123";
ProductPlace = "123";
Console.WriteLine("我是一辆{0}车,{1},产地是{2}", Name, Color, ProductPlace);
}
随便为属性赋个值,就好了。 //输出 我是一辆奔驰车,蓝颜色,产地是德国