[英]c# adding two lists in recursive return
我正在实施递归中值割算法https://en.wikipedia.org/wiki/Median_cut并遇到问题,我的返回消息说“运算符+不能应用于类型为List和List的操作数”。
这是我的代码,因此您可以洞悉我的要求:
public static List<Color> Cut(List<Color> input,int n)
{
if (n == 1)
{
//creating List<Color> containing 1 color element which is
//average of all colors from input and returning this 1 element
//list ending our recursion
}
else
{
SortWithRespectToWidestChannel(input)
int median = input.Count / 2;
List<Color> l1 = new List<Color>();
List<Color> l2 = new List<Color>();
l1.AddRange(input.GetRange(0, median));
l2.AddRange(input.GetRange(median, input.Count - median));
return Cut(l1, n / 2) + Cut(l2, n / 2); // <---**here is problem**
}
那么您知道我该如何解决我的问题? 先感谢您。
如果要将所有颜色都放在一个列表中,请尝试此操作。
更改:
return Cut(l1, n / 2) + Cut(l2, n / 2); // <---**here is problem**
至
var result = new List<Color>();
result.AddRange(Cut(l1, n / 2));
result.AddRange(Cut(l2, n / 2));
return result;
如果我纠正有关您的问题的事情,请给我反馈。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.