gpt4 book ai didi

c# - 如何在 string.format 中显示 List 的所有内容?

转载 作者:太空宇宙 更新时间:2023-11-03 21:26:50 24 4
gpt4 key购买 nike

这是一个针对不同餐厅以及它们在一周中的哪几天营业的小型应用程序。在我的界面中,一周中的每一天都有复选框。我想在每个选定的天数(选中)框中输出 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);

关于c# - 如何在 string.format 中显示 List<DayOfWeek> 的所有内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26466367/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com