繁体   English   中英

如何在C#的console.writeline内以string.format语法包含方法?

[英]How to include a method in a string.format syntax inside a console.writeline in C#?

我有一个显示类似以下内容的方法:

public void display(){

Console.Writeline("Message");
}

我应该将其包含在使用string.format的console.writeline中( <<>>里面的样子):

int CodeName = 52;
Console.WriteLine("Mutant Name: {0} ------ Message: {1}", CodeName, <<dispplay()>>);

尝试通过使display方法返回值来调用display方法。

像这样:

public string display() 
{
    return "Message";
}

int CodeName = 52;

Console.WriteLine(string.Format("Mutant Name: {0} ------ Message: {1}", CodeName, display()));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM