如何修复 C# 锯齿状数组类型转换错误
How to fix C# Jagged arrays Type Conversion Error
本文来自微软在edx上的C#数据结构与算法课程
"锯齿状数组
交错数组只是数组的数组,每个数组的大小可以变化。"
int[][] jaggedArray = new int[10][];
jaggedArray[0] = new Type[5];//cannot implicitly convert type 'system.Type[]' to 'int[]'
jaggedArray[1] = new Type[7];//cannot implicitly convert type 'system.Type[]' to 'int[]'
jaggedArray[9] = new Type[21];//cannot implicitly convert type 'system.Type[]' to 'int[]'
预期结果:没有错误
实际结果:无法将类型 'system.Type[]' 隐式转换为 'int[]'
请帮忙
我会报到课程
感谢您的评论和回答。他们有帮助。
正如评论所说,System.Type 与 int 不同,我想你想要这样的东西:
Type[][] jaggedArray = new Type[10][];
jaggedArray[0] = new Type[5];
jaggedArray[1] = new Type[7];
jaggedArray[9] = new Type[21];
本文来自微软在edx上的C#数据结构与算法课程
"锯齿状数组 交错数组只是数组的数组,每个数组的大小可以变化。"
int[][] jaggedArray = new int[10][];
jaggedArray[0] = new Type[5];//cannot implicitly convert type 'system.Type[]' to 'int[]'
jaggedArray[1] = new Type[7];//cannot implicitly convert type 'system.Type[]' to 'int[]'
jaggedArray[9] = new Type[21];//cannot implicitly convert type 'system.Type[]' to 'int[]'
预期结果:没有错误
实际结果:无法将类型 'system.Type[]' 隐式转换为 'int[]'
请帮忙
我会报到课程
感谢您的评论和回答。他们有帮助。
正如评论所说,System.Type 与 int 不同,我想你想要这样的东西:
Type[][] jaggedArray = new Type[10][];
jaggedArray[0] = new Type[5];
jaggedArray[1] = new Type[7];
jaggedArray[9] = new Type[21];