如何输出我的属性 [英] How to output my properties

查看:65
本文介绍了如何输出我的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我有这个代码,我想使用我的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.

推荐答案

'是针对c#6而我不知道如何替换它。第二,当我WriteLine一个属性时,我得到0作为输出。





' 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});
}

}
"{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.


你的构造函数中缺少这个



You are missing this in your constructor

public Car(decimal Price, string Model, BrandType brand)
		{
			this.Price = Price;
			this.Model = Model;
			this.Brand = brand;

		}


这篇关于如何输出我的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆