首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

关于C#的代码有关问题

2012-09-16 
关于C#的代码问题这段代码什么意思?求高人解释:ListBoundaryCell list new ListBoundaryCell(4)lis

关于C#的代码问题
这段代码什么意思?求高人解释:
List<BoundaryCell> list = new List<BoundaryCell>(4);
list.Add(cellUp);
list.Add(cellDown);
list.Add(cellLeft);
list.Add(cellRight);
HashSet<BoundaryCell> boundaryCells = new HashSet<BoundaryCell>(list);
这是用C#写的。
BoundaryCell是边界像素,cellUp、cellDown、cellLeft、cellRight分别是上下左右相邻像素。不过这不重要……求解释最后一句。我感觉最后一句HashSet的值的类型应该是List而不是BoundaryCell。求高人指点。

[解决办法]
将list列表加入HashSet,比如如下操作都是一样的,只不过写法不一致

C# code
 List<string> list = new List<string>() { "Ferrari", "McLaren", "Toyota", "BMW", "Renault", "Honda" };                HashSet<string> companyTeams = new HashSet<string>() { "Ferrari", "McLaren", "Toyota", "BMW", "Renault", "Honda" };                HashSet<string> companyTeams1 = new HashSet<string>(list);
[解决办法]
既然是泛型,你凭什么任务人家应该是什么
因为 list 中是BoundaryCell,所以才有这么一句 HashSet<BoundaryCell>(list),转换list为HashSet<BoundaryCell>

热点排行