在我的應用程序中,我確定網絡更改發生時。我有,我用一些示例代碼,但我想結果字符串以一定的方式格式化如何格式化字符串
string change = string.Empty;
switch (e.NotificationType)
{
case NetworkNotificationType.InterfaceConnected:
change = "Connected to ";
break;
case NetworkNotificationType.InterfaceDisconnected:
change = "Disconnected from ";
break;
case NetworkNotificationType.CharacteristicUpdate:
change = "Characteristics changed for ";
break;
default:
change = "Unknown change with ";
break;
}
string changeInformation = String.Format(" {0} {1} {2} ({3})",
DateTime.Now.ToString(), change, e.NetworkInterface.InterfaceName,
e.NetworkInterface.InterfaceType.ToString());
// We are making UI updates, so make sure these happen on the UI thread.
Dispatcher.BeginInvoke(() =>
{
Changes.Add(changeInformation); //Changes contains the changeInformation
});
目前的結果看起來像
但這不是在格式化好所有,而且往往會有時混亂。我希望能夠對其進行格式化,以使DateTime.Now.ToString()
位於最上面,然後是change
位於下一行,然後是e.NetworkInterface.InterfaceName
和e.NetworkInterface.InterfaceType.ToString()
。我怎麼能這樣做?
使用換行符...( \ n幫助) – Vogel612
'String.Format(「{0} \ n {1} \ n {2}({3})」,...' –