我想知道是否有更好的方法来缩短我的代码或将其重构为可维护或可用的代码。不做List,然后命名,依此类推..我可以做什么来改进我的代码更有意义,而不是做很多像List这样的事情。如果有一个好的方法来做这件事?将其创建为帮助器。
这段代码的目的是存储每个月每天的数据,期望它们在循环中。它们每天都会被一个数据填充。
var outputPerDays = new List<OutputPerDay>();
var day1 = new List<Pricing>();
var day2 = new List<Pricing>();
var day3 = new List<Pricing>();
var day4 = new List<Pricing>();
var day5 = new List<Pricing>();
var day6 = new List<Pricing>();
var day7 = new List<Pricing>();
var day8 = new List<Pricing>();
var day9 = new List<Pricing>();
var day10 = new List<Pricing>();
var day11 = new List<Pricing>();
var day12 = new List<Pricing>();
var day13 = new List<Pricing>();
var day14 = new List<Pricing>();
var day15 = new List<Pricing>();
var day16 = new List<Pricing>();
var day17 = new List<Pricing>();
var day18 = new List<Pricing>();
var day19 = new List<Pricing>();
var day20 = new List<Pricing>();
var day21 = new List<Pricing>();
var day22 = new List<Pricing>();
var day23 = new List<Pricing>();
var day24 = new List<Pricing>();
var day25 = new List<Pricing>();
var day26 = new List<Pricing>();
var day27 = new List<Pricing>();
var day28 = new List<Pricing>();
var day29 = new List<Pricing>();
var day30 = new List<Pricing>();
var day31 = new List<Pricing>();
[Serializable]
public class OutputPerDay
{
public List<Pricing> Day1 { get; set; }
public List<Pricing> Day2 { get; set; }
public List<Pricing> Day3 { get; set; }
public List<Pricing> Day4 { get; set; }
public List<Pricing> Day5 { get; set; }
public List<Pricing> Day6 { get; set; }
public List<Pricing> Day7 { get; set; }
public List<Pricing> Day8 { get; set; }
public List<Pricing> Day9 { get; set; }
public List<Pricing> Day10 { get; set; }
public List<Pricing> Day11 { get; set; }
public List<Pricing> Day12 { get; set; }
public List<Pricing> Day13 { get; set; }
public List<Pricing> Day14 { get; set; }
public List<Pricing> Day15 { get; set; }
public List<Pricing> Day16 { get; set; }
public List<Pricing> Day17 { get; set; }
public List<Pricing> Day18 { get; set; }
public List<Pricing> Day19 { get; set; }
public List<Pricing> Day20 { get; set; }
public List<Pricing> Day21 { get; set; }
public List<Pricing> Day22 { get; set; }
public List<Pricing> Day23 { get; set; }
public List<Pricing> Day24 { get; set; }
public List<Pricing> Day25 { get; set; }
public List<Pricing> Day26 { get; set; }
public List<Pricing> Day27 { get; set; }
public List<Pricing> Day28 { get; set; }
public List<Pricing> Day29 { get; set; }
public List<Pricing> Day30 { get; set; }
public List<Pricing> Day31 { get; set; }
}发布于 2019-04-03 10:09:21
你可以这样做:
[Serializable]
public class OutputPerDay
{
public List<string>[] _pricesPerDay = new List<string>[3];
public OutputPerDay()
{
for(int index = 0; index < 3; index++)
{
_pricesPerDay[0] = new List<string>();
}
}
public List<string> Day1 => _pricesPerDay[0];
public List<string> Day2 => _pricesPerDay[1];
public List<string> Day3 => _pricesPerDay[2];
}https://stackoverflow.com/questions/55485820
复制相似问题