开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜