List<int[]> list = new List<int[]>(); int maxArrayLength = 8; for(int i = 8;i > 0; i = i / 2) { list.Add(new int[i]); } int[][] result = = list.ToArray();
看看交错数组, 最好用list;
//保存数组的变量 arrs Dictionary<int,byte[]> arrs= new Dictionary<int,byte[]>();void Create(int len) { int i = len; while(i>1) { //建立数组 byte[] arr = new byte[i]; //添加到字典变量 arrs.Add(i,arr); i = i / 2; } }
class Program { static void Main(string[] args) { int max = 8; object ok = arrary(max); Console.WriteLine(ok); } /// <summary> /// 参数是偶数的数组 /// </summary> /// <param name="n">偶数</param> /// <returns></returns> public static object arrary(int n) { List<object> ay = new List<object>(); ay = AddList(ay, n); if ((n / 2) >= 1) { for (int index = 0; index < ay.Count;index++ ) { ay[index] = arrary(n / 2); } } return ay.ToArray(); } public static List<object> AddList(List<object> o, int index) { int i=0; while (true) { o.Add(0); i++; if (i == index) break; } return o; }
int maxArrayLength = 8;
for(int i = 8;i > 0; i = i / 2)
{
list.Add(new int[i]);
}
int[][] result = = list.ToArray();
最好用list;
Dictionary<int,byte[]> arrs= new Dictionary<int,byte[]>();void Create(int len)
{
int i = len;
while(i>1)
{
//建立数组
byte[] arr = new byte[i];
//添加到字典变量
arrs.Add(i,arr);
i = i / 2;
}
}
class Program
{
static void Main(string[] args)
{
int max = 8;
object ok = arrary(max);
Console.WriteLine(ok);
} /// <summary>
/// 参数是偶数的数组
/// </summary>
/// <param name="n">偶数</param>
/// <returns></returns>
public static object arrary(int n)
{
List<object> ay = new List<object>();
ay = AddList(ay, n);
if ((n / 2) >= 1)
{
for (int index = 0; index < ay.Count;index++ )
{
ay[index] = arrary(n / 2);
}
}
return ay.ToArray();
} public static List<object> AddList(List<object> o, int index)
{
int i=0;
while (true)
{
o.Add(0); i++;
if (i == index)
break;
}
return o;
}