我尝试使用递归函数并输出结果值的列表。 这是我想出的密码,但它给了我
Error (CS0161): 'Script_Instance.wrapper(int, int, Grasshopper.DataTree, System.Collections.Generic.List)': not all code paths return a value (line 87)
public List<int> wrapper(int br, int depth, DataTree<int> topo, List<double> vals)
{
List<int> collection = new List<int>();
collection.Add(br);
if (depth > 0)
{
double[] area = new double[vals.Count - 1];
for (int i = 0;i < topo.Branches[br].Count;i++)
{
area[i] = vals[topo.Branch(br)[i]];
}
double Im = area.Max();
int IofMaxArea = area.ToList().IndexOf(Im);
collection.Add(IofMaxArea);
// wrapper(topo.Branch(br)[IofMaxArea], de, topo, vals);
wrapper(topo.Branch(br)[IofMaxArea], depth-1, topo, vals);
}
if (depth == 0)
{
return collection;
}
}
我正在尝试改进一个python脚本,它运行得很好,但速度太慢,无法满足我的需要。这是python代码。在
^{pr2}$这是Rhino3d+蚱蜢。在
这里的代码确保
depth
的任何正值都会导致方法再次被调用:超越
if
块的唯一方法是depth
小于或等于0。在此之后,不需要单独验证depth
的值。在所以改变这个:
^{pr2}$为此:
编译器正在抱怨,因为您没有指定如果
depth
不等于0,则返回什么值。即使在逻辑上你知道你的方法最终会返回一个值,编译器却不会相关问题 更多 >
编程相关推荐