コードを最適化しようとしています。私は持っていますenum
:
enum Months { Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec }
そして、既製のクラスのオブジェクトを含む次のコード:
oi.Jan = Math.Round(Convert.ToDecimal(adjAllocation[0]), 2).ToString();
oi.Feb = Math.Round(Convert.ToDecimal(adjAllocation[1]), 2).ToString();
oi.Mar = Math.Round(Convert.ToDecimal(adjAllocation[2]), 2).ToString();
oi.Apr = Math.Round(Convert.ToDecimal(adjAllocation[3]), 2).ToString();
oi.May = Math.Round(Convert.ToDecimal(adjAllocation[4]), 2).ToString();
oi.Jun = Math.Round(Convert.ToDecimal(adjAllocation[5]), 2).ToString();
oi.Jul = Math.Round(Convert.ToDecimal(adjAllocation[6]), 2).ToString();
oi.Aug = Math.Round(Convert.ToDecimal(adjAllocation[7]), 2).ToString();
oi.Sep = Math.Round(Convert.ToDecimal(adjAllocation[8]), 2).ToString();
oi.Oct = Math.Round(Convert.ToDecimal(adjAllocation[9]), 2).ToString();
oi.Nov = Math.Round(Convert.ToDecimal(adjAllocation[10]), 2).ToString();
oi.Dec = Math.Round(Convert.ToDecimal(adjAllocation[11]), 2).ToString();
私はこのようなことをしようとしています(疑似コード):
oi.[Months[i]] = Math.Round(Convert.ToDecimal(adjAllocation[0]), 2).ToString();
オブジェクトを作成しているクラスに配列を入れることはできません。私が呼び出している既製のクラスの文字列であるプロパティが必要です。