該代碼如何被轉換爲C#,具體如何在C#中實現sprintf
?c#.NET和sprintf語法
string output = "The user %s logged in";
string loggedIn = "is";
string loggedOut = "isn't";
if (TheUser.CheckStatus())
{
output = sprintf(output, loggedIn);
}
else
{
output = sprintf(output, loggedOut);
}
return output;
我期待看到"The user isn't logged in"
如果TheUser.CheckStatus()
是false
。
謝謝你的參考! – Jimmyt1988
或作爲一個單一的班輪:'返回string.Format(「用戶{0}登錄」,TheUser.CheckStatus()?「是」:「不是」);' – Stormenet