我有一堆整数,我想把它们加到一个特定的组中。假设每组不超过100个整数。我希望能够添加一个新的组,如果需要(最多100个组)。我希望能够通过索引访问任何组中的所有元素(即group2.element3)。我还应该能够对每个组中的元素进行排序。
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Elements
{
private int[] values;
public int[] Values
{
get
{
return values;
}
set
{
values = value;
}
}
}
class Solution {
static void Main(String[] args) {
Elements[] groups = new Elements[100];
groups[0].SetValue(5, 1); // fill group[0] elements[1] with value 5
int v = groups[0].GetValue(2); // read value located at index 2
}
}对于组,也许我可以做一个数组列表。我想我可以创建一个名为Elements的类,并为每个新组实例化一个新元素。如果我想使用Elements类,您能提供有关如何修复此代码的信息吗?
https://stackoverflow.com/questions/41413555
复制相似问题