、Arrayとして返された列挙値のインデックスを取得するには?私はこのコードを持つ2つの問題を抱えている
最初は、それは次のように印刷し、私はそれを印刷するとき、6日目には順序ではないことをされています
On Day1:Temperature was12
On Day2:Temperature was13
On Day3:Temperature was15
On Day4:Temperature was17
On Day5:Temperature was18
On Day7:Temperature was19
On Day8:Temperature was20
On Day9:Temperature was21
On Day6:Temperature was22
On Day10:Temperature was23
The Minimum Tempreature was 12,
The Maximum temperature was 23,
The average Temperature was 18,
第二の問題は、私は印刷するときということです
The Minimum Tempreature was 12, at Day 1
The Maximum temperature was 23,at Day 10
私はその値に基づいて、列挙型の名前を取得できますか:日は、私はまた、最小値と最大温度は、このような場所を土気した日を含めたいですか?
これは、
上記プリントするためのコードでこのコードは、パラメータとして列挙(日間、温度)をとり、最大および平均のそれらの関連温度と最小との日、印刷....
// if user select February
if (DropDownList1.SelectedValue.ToString()== "February")
{
ShowsTempreatures(FebruaryMonth.Day2);
}
// The method which print and shows temperatures and minimum and maximum...
private void ShowsTempreatures(Enum February)
{
int Minimumtemperture = 40;
int Maximumtemperture = 0;
int total = 0;
int averageTemperatures = 0;
// Return the values of Enum as an Array
Array januaryData = Enum.GetValues(February.GetType());
for (int i = 0; i < januaryData.Length; i++)
{
//printing the Days and Temperatures of enum February
Label1.Text += string.Format("On {0}:Temperature was{0:D}<br/>", januaryData.GetValue(i));
//finding out minimum and maximum and average temperatures
int MonthTemp = (int)januaryData.GetValue(i);
if (MonthTemp<Minimumtemperture)
{
Minimumtemperture = MonthTemp;
}
if (MonthTemp>Maximumtemperture)
{
Maximumtemperture = MonthTemp;
}
total = total + MonthTemp;
}
int totaltempretures = januaryData.Length;
averageTemperatures = (total/totaltempretures);
// printing the minimum,maximum and average temperature
Label1.Text += string.Format("The Minimum Tempreature was {0},<br/> The Maximum temperature was {1},<br/> The average Temperature was {2},<br/> ",
Minimumtemperture, Maximumtemperture, averageTemperatures);
}
private enum FebruaryMonth
{
Day1 = 12,
Day2 = 13,
Day3 = 15,
Day4 = 17,
Day5 = 18,
Day6 = 22,
Day7 = 19,
Day8 = 20,
Day9 = 21,
Day10 = 23
}
「enum February」を投稿できますか? –
申し訳ありません投稿するのを忘れました投稿を編集しました – Mohsen