这是一个针对不同餐厅的小型应用程序,它们一周中的哪几天开放。在界面中,我有一周中每一天的复选框。我想在每个选定的天(选中)框中输出一个string.Format
。这可能吗?
这是他选中复选框的代码:
foreach (CheckBox cb in grpDaysOpen.Controls) // Add days of week that the restaurant is open
{
DayOfWeek enumConvertedSuccessfully; // Will contain good enums soon
if (cb.Checked && Enum.TryParse<DayOfWeek>(cb.Text, out enumConvertedSuccessfully))
favoriteDiningPlace.OpenDays.Add(enumConvertedSuccessfully);
}
这是当前的替代
ToString
:return string.Format(
"{0} is a chian of {1} with a seating capacity of {2}:\r\nSmoking is {3}. Last month's sales were {4}, while last months costs were {5}. \r\nThe restaurant is open {6}",
this.Name,
this.Chain,
this.SeatingCapacity,
this.Smoking,
this.LastMonthSales,
this.LastMonthCosts,
this.OpenDays);
我不知道是否需要在其中包含其他任何代码。如果您需要澄清,请告诉我。当前上述
ToString
输出“ system.collections.generic.list` [System.DayOfWeek]”
对于
this.OpenDays
。 最佳答案
List<DayOfWeek> d = new List<DayOfWeek> { DayOfWeek.Monday, DayOfWeek.Saturday };
string res = string.Join(", ", d);