我重写了我的 ToString() 方法,我的类包含许多字段。
我只能在最后一个字符串之后有新行,并且只能将变量放在下一行。
注意 - 这仅用于视觉目的,我不希望在打印之间分隔一行.. 只在我的 21" 屏幕上看到整行而不滚动。
这有效:
public override string ToString()
{
return String.Format("{0}, IsAccessible = {1}, NetworkAddress = {2}, Manufacturer = {3}, Model = {4}, Firmware = {5}, Driver = {6}, MacAddress = {7}, Scenes count = {8}",
base.ToString(), IsAccessible, NetworkAddress, Manufacturer, Model, Firmware, Driver, MacAddress, Scenes.Count);
}
但这不起作用(相同的代码,仅在第 4 个参数后按回车键):
public override string ToString()
{
return String.Format("{0}, IsAccessible = {1}, NetworkAddress = {2}, Manufacturer = {3}, Model = {4},
Firmware = {5}, Driver = {6}, MacAddress = {7}, Scenes count = {8}",
base.ToString(), IsAccessible, NetworkAddress, Manufacturer, Model, Firmware, Driver, MacAddress, Scenes.Count);
}