using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace listTst
{
class Program
{
static void Main(string[] args)
{
var sw = Stopwatch.StartNew();
var array = new List<Storage>()
{
new Storage{ Id = , Name = "A" },
new Storage{ Id = , Name = "B" },
new Storage{ Id = , Name = "C" },
new Storage{ Id = , Name = "D" },
new Storage{ Id = , Name = "E" },
new Storage{ Id = , Name = "F" },
new Storage{ Id = , Name = "G" },
new Storage{ Id = , Name = "H" },
new Storage{ Id = , Name = "I" },
}; var result = new List<Group>();
array.ForEach(a => { result.Add(new Group(a)); });
for (int count = ; count <= array.Count; count++)
{
Test(result, array, , count);
}
sw.Stop(); foreach (var group in result)
{
Console.WriteLine(group.Name);
}
Console.WriteLine($"组合数量:{result.Count}");
Console.WriteLine($"耗时:{sw.ElapsedMilliseconds}ms");
Console.ReadLine();
} static void Test(List<Group> result, List<Storage> array, int begin, int count)
{
var list = new List<Storage>();
var end = begin + count - ;
if (end > array.Count) return;
for (int i = begin; i < end; i++)
{
list.Add(array[i]);
}
if (list.Count < count)
{
for (int index = end; index < array.Count; index++)
{
var group = new Group(list);
group.Storages.Add(array[index]);
result.Add(group);
}
} if (++begin < array.Count) Test(result, array, begin, count);
} class Group
{
public Group(Storage storage)
{
Storages.Add(storage);
}
public Group(List<Storage> list)
{
Storages.AddRange(list);
}
public string Name => string.Concat(Storages.Select(a => a.Name));
public List<Storage> Storages = new List<Storage>();
} class Storage
{
public int Id { get; set; }
public string Name { get; set; }
}
}
}

最新文章

  1. 【KeyCode 键码】
  2. [linux系统]--搭建ftp服务器并且 创建用户 设置密码
  3. c++之string.find(string)
  4. 转: javascript实现全国城市三级联动菜单代码
  5. 如何在 Linux 中清除缓存(Cache)
  6. 如何使用CSS3创建一个漂亮的图标
  7. 使用DbVisualizer 8 连接Oracle数据库
  8. inline(内联元素)和block(块级元素) 的区别
  9. 输入整数n(n&lt;=10000),表示接下来将会输入n个实数,将这n个实数存入数组a中。请定义一个数组拷贝函数将数组a中的n个数拷贝到数组b中。
  10. 去掉eclipse js 错误提示
  11. weblogic上部署应用程序
  12. 告示:CSDN博客通道支持Windows Live Writer写blog离线好友
  13. cct,web技术
  14. poj2236(并查集)
  15. Linux磁盘分区,目录树,文件系统的关系(转)
  16. C:函数:功能:实现字符数组中所有字母的倒序存放并输出
  17. 当PsychicBoom_发觉自己是个大SB的时候……
  18. Ubuntu 安装 Docker CE
  19. 第16月第10天 poco target
  20. NDK学习笔记(三):DynamicKnobs的机制

热门文章

  1. Spark On YARN(Yarn-Cluster模式)启动流程源码分析(二)
  2. (3)Linux命令分类汇总(7~12)
  3. pytest.mark.parametrize()参数化应用二,读取json文件
  4. 【ARM-Linux开发】 uboot启动阶段修改启动参数方法及分析
  5. leveldb单元测试之宏定义源码剖析
  6. 主成分分析(PCA)与线性判别分析(LDA)
  7. (模板)poj3461(kmp模板题)
  8. 如何查看class文件的编译jdk版本号
  9. Kubernetes---容器的生命周期
  10. Web应用中访问WEB-INF下的资源