Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 比较两个字节数组,找出哪个更大_C#_Arrays_Jagged Arrays - Fatal编程技术网

C# 比较两个字节数组,找出哪个更大

C# 比较两个字节数组,找出哪个更大,c#,arrays,jagged-arrays,C#,Arrays,Jagged Arrays,我有一个锯齿状的字节数组字节[][],我试图获取它的子数组项的最大值 我创建了一个方法: private byte[] Max(byte[][] arrBytes) { var max = arrBytes[0]; foreach (var arr in arrBytes) { if (max != null && arr != null) if () // => How to say max > arr

我有一个锯齿状的字节数组
字节[][]
,我试图获取它的子数组项的最大值

我创建了一个方法:

private byte[] Max(byte[][] arrBytes)
{
    var max = arrBytes[0];
    foreach (var arr in arrBytes)
    {
        if (max != null && arr != null)
            if () // => How to say max > arr
                max = arr;
    }
    return max;
}
如何从上述方法返回最大字节数组

编辑 对于所有询问单词
biger
的度量或定义是什么的人来说,我说交错数组包含SQLServer(varbinary(8))的(时间戳)数据类型,数据如下所示


字节数组表示(例如:0x00000000013F3F3F)

也许转换为
long
并进行比较会对您有所帮助

// Note: you should ensure that the arrays have at least 8 bytes!
// Although from your edits, it sounds like your "jagged" array isn't jagged at all
if (BitConverter.ToUInt64(max,0) > BitConverter.ToUInt64(arr,0)) 
{
    // do whatever.
}

但要注意字节顺序的差异。如果您的时间戳只是一个刻度数,这将起作用。如果它实际上是一个日期,你需要找出适当的转换。

你在找这样的东西吗

    private byte[] Max(byte[][] arrBytes)
    {
        byte[] max = new byte[arrBytes.GetLength(0)];
        int i = 0;
        foreach (byte[] arr in arrBytes)
        {
            byte m = 0;
            foreach (byte b in arr)
            {
                m = Math.Max(m, b);
            }
            max[i] = m; ++i;
        }
        return max;
    }

您如何定义一个数组大于另一个数组?@SVI您告诉我们您想找出哪个数组“更大”。您必须定义Biger对您的应用程序意味着什么。长度(元素数量)更大?就所有元素的总和而言更大?你必须知道你想要什么。你想要最大长度、最大平均值、最大最大/最小值的数组吗?或者你想要锯齿状数组中所有字节的最大值的数组?我认为问题在于标题有误导性。问题是最大值,看起来只有一个锯齿状数组,OP只需要数组中的任意一个最大值。也许???我认为您应该尝试将
字节[]
转换为时间戳值,并比较这些值以找到最大值。