我试图找到一种方法可以将提取的数组列表扩展到排序列表?这是我下面的代码,它根据每个候选人水平显示结果,但是我看到了如何将其合并到 SortedList 中,在那里我可以按区域排序?
我尝试了排序列表的一些变体,但是我唯一的成功是垂直打印出第一列(仅)。
X 012
X 075
X 050
X 040
string[] voting = { "X012033001140", "C075100026080", "A050070060100", "Q040088050090" };
//int length = voting.Length;
int starter = 0;
int total_a = 0;
int total_b = 0;
int total_c = 0;
int total_d = 0;
int precinct_x = 0;
Console.WriteLine("VOTING RESULTS");
Console.WriteLine("--------------------");
Console.WriteLine("Precinct\tCandidate A \tCandidate B\tCandidate C\tCandidate D\tTotal Precinct Votes");
while (starter < voting.Length)
{
string precinct = voting[starter].Substring(0, 1);
string cand_a = voting[starter].Substring(1, 3);
string cand_b = voting[starter].Substring(4, 3);
string cand_c = voting[starter].Substring(7, 3);
string cand_d = voting[starter].Substring(10, 3);
int counter = 0;
//Converting the vote counts from strings to ints in order to calculate
int a = Convert.ToInt32(cand_a);
int b = Convert.ToInt32(cand_b);
int c = Convert.ToInt32(cand_c);
int d = Convert.ToInt32(cand_d);
precinct_x = a + b + c + d;
counter++;
//Console.WriteLine(precinct);
Console.WriteLine(precinct + "\t\t" + cand_a + "\t\t" + cand_b + "\t\t" + cand_c + "\t\t" + cand_d + "\t\t" + precinct_x + "\t");
double precinct_total = Convert.ToDouble(precinct_x);
//This is required in order to continuously loop up to the maximum of the voting Length
starter = starter + 1;
//Calculations for Candidate A
total_a = total_a + a;
total_b = total_b + b;
total_c = total_c + c;
total_d = total_d + d;
}
Console.WriteLine("\nTOTAL RESULTS");
Console.WriteLine("--------------------------------------------------------------------------------");
Console.WriteLine("\t\t" + total_a + "\t\t" + total_b + "\t\t" + total_c + "\t\t" + total_d);
Console.ReadLine();