C# String.format()和$的使用

$出现在c#6.0。原来我们格式化字符串是这么写的:

public string ID { set; get; }
public string Name { set; get; }
public string FullName => string.Format("{0}-{1}",ID,Name);

现在我们可以这么写:

        public string ID { set; get; }
        public string Name { set; get; }
        public string FullName => $"{ID}-{Name}";

两种写法是等价的。

猜你喜欢

转载自blog.csdn.net/dap769815768/article/details/83033551