在多个数组中查找公用值,或列出VB.NET [英] Find Common Values in several arrays, or lists VB.NET

查看:50
本文介绍了在多个数组中查找公用值,或列出VB.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用PHP查找多个数组中的公用值

我需要做的很多,但是在PHP中,我需要VB.

Pretty much does what I need, but in PHP, I need VB.

我的情况是我试图基于多个库存位置创建一个智能的库存拣选系统.

My situation is I am trying to create an intelligent stock pick system based on multiple stock locations.

在开具发票时,我们会遍历已开具发票的项目,并检查库存数据库中的可用库存.

At the point of invoicing, we loop through the items invoiced and check the stock database for available stock.

如果发票上的所有项目都可以从库存位置1取货,那么所有物品都应从库存位置1取货...等等.

If all items on the invoice are available to pick from stock location 1, then all should be picked from stock location 1... etc.

如果除了一个或两个位置以外,所有其他物品都可以从库存位置1获得,则从库存位置1提取所有库存,除了应该从可用库存量最高的位置提取的例外.

If all most items are available from stock location 1 except one or two, then pick all stock from stock location 1 except for the exceptions which should be picked from the location with the highest available stock.

查找可用的最高库存很简单,但是我无法弄清楚如何从多个位置分析库存量并找到普通库存位置.

Finding highest available stock is simple, but I can't work out how to analyse the stock availability from multiple locations and finding the common stock locations.

我可以创建一组这样的数组

I can create a set of arrays like this

Item ID    |     Available Stock Locations
    1      |        2, 3, 5
    2      |        1, 2, 6
    3      |        2, 3, 4
    4      |        1, 2 ,3 

我如何比较那些位置列表以发现 2 是所有四个共同的?

How to I compare those location lists to find that 2 is common to all four?

第二,如果一个物料没有通用的库存位置,我将如何识别该物料,以便我可以回头找到该物料的最高可用库存水平?

Secondly, if one Item did not have a common stock location, how would I identify that item so I can go back and find the highest available stock level for it?

推荐答案

与PHP一样,您可以相交数组以查找通用值.多亏了LINQ,这在VB中相当容易:

As in PHP, you can intersect arrays to find common values. Thanks to LINQ, this is fairly easy in VB:

Dim array1 = {2, 3, 5}
Dim array2 = {1, 2, 6}
Dim array3 = {2, 3, 4}
Dim array4 = {1, 2, 3}

Dim commonItems = array1.Intersect(array2).Intersect(array3).Intersect(array4)

commonItems 现在是包含所有常见商店位置的 IEnumerable(Integer).

commonItems is now an IEnumerable(Of Integer) containing all common store locations.

这篇关于在多个数组中查找公用值,或列出VB.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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