问题描述
你好,我有这个代码,我想使用我的Introduce方法,但首先我不能WriteLine多个属性,因为'$'是c#6,我不知道如何替换它。第二,当我WriteLine一个属性时,我得到0作为输出。
Hello,I have this code and I would like to use my Introduce method,but first I can't WriteLine more than one property as '$' is for c# 6 and I don't know how to substitute it. Second when I WriteLine a single Property I get 0 as output.
class Program
{
static void Main(string[] args)
{
Car car = new Car(999, "g", BrandType.Lada);
car.Introduce();
}
}
public class Car
{
public string Model { get; set; }
public BrandType Brand { get; set; }
public decimal Price { get; set; }
public Car(decimal Price, string Model, BrandType brand)
{
}
public void Introduce()
{
Console.WriteLine($"{this.Brand}-{this.Price}-{this.Model}");
}
}
我尝试过:
我尝试添加套接字
Console.WriteLine({0},this.Brand);
但它没有做任何事情并且再次输出0。
What I have tried:
I tried adding sockets
Console.WriteLine("{0}",this.Brand);
but it does nothing and outputs 0 again.
推荐答案
class Program
{
static void Main(string[] args)
{
Car car = new Car(999, "g", BrandType.Lada);
car.Introduce();
}
}
public class Car
{
public string Model { get; set; }
public BrandType Brand { get; set; }
public decimal Price { get; set; }
public Car(decimal Price, string Model, BrandType brand)
{
}
public void Introduce()
{
Console.WriteLine(
我尝试过:
我尝试添加套接字
Console.WriteLine({0},this.Brand);
但它什么也没做,再次输出0。
What I have tried:
I tried adding sockets
Console.WriteLine("{0}",this.Brand);
but it does nothing and outputs 0 again.
public Car(decimal Price, string Model, BrandType brand)
{
this.Price = Price;
this.Model = Model;
this.Brand = brand;
}
这篇关于如何输出我的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!