开发者

How can I read a CSV file into a System.Array that has already been initialized?

I want to create an array and initialize it with for example for testing:

string[] myList= new string[]
{       "item1",
        "item2",        
}

If later 开发者_如何学运维I want to fill it from a csv file, will I be able to add any number of items to it ?

I don't want to use dynamic array because initialization syntax with .add method is not as convenient when I have to do it by hand.


Arrays have a fixed size, so you will not be able to add any amount of numbers to it. The closest thing you can do is to create an array that is large enough to store the amount of numbers you will be most likely generating but this is highly inefficient and also prone to errors if you generate more numbers than you have initially anticipated.

You will have to use a dynamic data structure such as an ArrayList, you might not find it convenient but it is much easier and makes you code look neater and more efficient.


no , you can not add multiple items.

What is the problem with List< string>

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜