关于Min Max使用linq对象的问题 - Visual Basic [英] Question about Min Max using linq objects - Visual Basic

查看:74
本文介绍了关于Min Max使用linq对象的问题 - Visual Basic的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!

是否可以使用linq创建一个数组(结果),如下例所示:

Is it possible to use linq to create an array (result) as the following example:

Sub Main()

Sub Main()

        Dim a()As Double = {10,20,30}

        Dim b()As Double = {11,12,23}
$
        Dim c()As Double = {22,1,3,6}

        Dim d()As Double = {2,3,6,1}

        Dim a() As Double = {10, 20, 30}
        Dim b() As Double = {11, 12, 23}
        Dim c() As Double = {22, 1, 3, 6}
        Dim d() As Double = {2, 3, 6, 1}

       昏暗的结果(3)As Double

        Dim result(3) As Double

        result(0)=最大值(a(0),b(0),c(0),d(0)) - 最小值(a(0),b(0),c(0),d(0))

       结果(1)=最大值(a(1),b(1),c(1),d(1)) - 最小值(a(1),b(1),c(1),d(1))

       结果(2)=最大值(a(2),b(2),c(2),d(2)) - 最小值(a(2),b(2),c(2),d(2))

       结果(3)=最大值(a(3),b(3),c(3),d(3)) - 最小值(a(3),b(3),c(3),d(3))

    End Sub

        result(0) = Maximum(a(0), b(0), c(0), d(0)) - Minimum(a(0), b(0), c(0), d(0))
        result(1) = Maximum(a(1), b(1), c(1), d(1)) - Minimum(a(1), b(1), c(1), d(1))
        result(2) = Maximum(a(2), b(2), c(2), d(2)) - Minimum(a(2), b(2), c(2), d(2))
        result(3) = Maximum(a(3), b(3), c(3), d(3)) - Minimum(a(3), b(3), c(3), d(3))
    End Sub

非常感谢您提供任何帮助。

Many thanks for any kind of help.

祝您好运,

推荐答案

不到三年过去了,问题就解决了......

Less than three years gone and the problem is solved...

请参阅我的c#解决方案:

See my c# solution:

            int[] a = {10, 20, 30, 0};
            int[] b = {11, 12, 23, 0};
            int[] c = {22, 1, 3, 6};
            int[] d = { 2, 3, 6, 1 };

            var minList = a.Zip(b, (x, y) => Math.Min(x, y)).Zip(c, (x, y) => Math.Min(x, y)).Zip(d, (x, y) => Math.Min(x, y));
            var maxList = a.Zip(b, (x, y) => Math.Max(x, y)).Zip(c, (x, y) => Math.Max(x, y)).Zip(d, (x, y) => Math.Max(x, y));
            var result = maxList.Zip(minList, (x, y) => x - y).ToArray();

顺便说一下:您的示例代码有两个拼写错误。数组a和b仅包含3个而不是4个元素。但是,您打算使用4个元素,因为您访问了(3)和b(3)。

By the way: your sample  code has two typos. Arrays a and b contain only 3 instead of 4 elements. However, you intended 4 elements, because you access a(3) and b(3).


这篇关于关于Min Max使用linq对象的问题 - Visual Basic的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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