添加和替换C#数组中的元素

use*_*003 1 c# arrays multidimensional-array

我必须使用C#中的一些数据进行操作.我的想法是将它们添加到数组中.该数组的元素将是(它将是包含3个元素的数组)

12, test11, comment12, comment23
15, test21, comment22, comment23
27, test31, comment32, comment33
... etc
Run Code Online (Sandbox Code Playgroud)

然后,我需要改变ie.元素15应该改为

15, test21, comment22A, comment23
Run Code Online (Sandbox Code Playgroud)

你能帮我解决一下如何使用这种阵列吗?

先感谢您!

Jon*_*eet 5

目前尚不清楚阵列的元素究竟是什么硬 - 但看起来确实存在一定数量的结构.我鼓励你将这个结构封装在一个新类型中 - 所以你可能会得到一个:

FooBar[] values = ...;
values[15] = new FooBar(15, "test21", "comment22A", "comment23");
Run Code Online (Sandbox Code Playgroud)

或者可能同样但有一个List<T>.多维数组(或数组数组)通常比一些封装良好的类型的单个集合更难处理.此外,您至少应该考虑使用比阵列更高级别的抽象 - 请参阅Eric Lippert的博客文章"被认为有些有害的阵列"以获取更多细节.

如果您的第一个值是某种标识符,您甚至可能希望将其更改为a Dictionary<int, FooBar>或a KeyedCollection<int, FooBar>.