简体   繁体   中英

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.
Please help me how I can enter information into 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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