简体   繁体   English

将项目添加到锯齿状数组

[英]Add Item to Jagged Array

It is a homework. 这是一项作业。
I want to store names and total votes of electoral candidates for country provinces. 我想存储国家省份的选举人姓名和总票数。
In this practice I should use arrays. 在这种情况下,我应该使用数组。
Since the number of candidates is not known I thinks I should use Jagged arrays. 由于候选人的数量未知,我认为我应该使用锯齿状数组。 But number of provinces is known so I wrote : 但是省的数目是已知的,所以我写道:

 int ProvincesCount = 30;
 string[][][] JaggedArray = new string[ProvincesCount][][];

I want to enter candidates names and their votes count into array with a Loop.Then I should determine top people in per province. 我想输入候选人姓名,他们的投票数将用Loop排列成阵列。然后确定每个省的头号人物。
Please help me how I can enter information into Array ? 请帮助我如何将信息输入Array?

Here you can find how to resize array. 在这里,您可以找到如何调整数组大小。 You might have to give an initial size. 您可能需要给出初始大小。 Its better to make a good guess for initial size so you don't have to resize alot. 最好对初始大小进行猜测,这样就不必重新调整大小。

Might I suggest you use classes to represent Provinces and Candidates if you have reached this topic. 如果您已达到此主题,我建议您使用类来代表省和候选人。

There is an array.resize method which you can use since it's homework. 还有 ,您可以使用,因为它是一个功课方法array.resize。 However, please remember when you get to more advanced topics this would not be the way to go and something like a linked list would serve better, depening on the application. 但是,请记住,当您进入更高级的主题时,这并不是要走的路,而像链表这样的东西会更好,取决于应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM