什么是从两个数组比较/排序项目最有效的方法是什么? [英] What is the most efficient way to compare/sort items from two arrays?

查看:172
本文介绍了什么是从两个数组比较/排序项目最有效的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个高效的实现问题。可以说我有两个数组:

一个阵列是在一所房子的所有可能的项目:桌子,椅子,电视,壁炉,床

另一种是物品在特定房子的阵列:表,电视机,床

我也有两个列表框:

1.列表框在内部项目 - 在有列表框中
2.列表框的项目不是在房子 - 需要列表框中

我需要以及已列出的项目在房子中的有列表框中为不在房子中的需要列表框中的项目。在我看来,这嵌套对于每一个循环将是一个开始,以解决这个问题,但我不是很确定需要嵌套这种情况。什么是要完成这样的任务最有效的方法是什么?

解决方案

  VAR allItems =(新[] {表,主席,电视,壁炉, 床});
VAR hasItems =(新[] {表,主席});

变种hasList = hasItems.ToList();
变种needsList = allItems.Except(hasItems).ToList();
 

I have a question about efficient implementation. Lets say I have two arrays:

One array is all possible items in a house: Table, Chair, TV, Fireplace, Bed

The other is an array of items in a particular house: Table, TV, Bed

I also have two list boxes:

1. listbox for items in the house - the "HAS" list box
2. listbox items not in the house - the "NEEDS" list box

I need to list the items already in the house in the "HAS" list box as well as the items that are NOT in the house in the "NEEDS" list box. It seems to me that nested "For each" loops would be a start to solving this problem but I am not exactly sure which case needs to be nested. What is the most efficient way to accomplish a task like this?

解决方案

var allItems = (new [] {"Table", "Chair", "TV", "Fireplace", "Bed"});
var hasItems = (new [] {"Table", "Chair"});

var hasList = hasItems.ToList();
var needsList = allItems.Except(hasItems).ToList();

这篇关于什么是从两个数组比较/排序项目最有效的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆