/// <summary> /// 读入字节数组中比较(ReanOnlySpan).net Core 3 /// System.Memory.dll /// </summary> /// <param name="file1"></param> /// <param name="file2"></param> /// <returns></returns> private static bool CompareByReadOnlySpan(string file1, string file2) { const int BBYTTES_TOREAD = 1024 * 10; using (FileStream fs1 = File.Open(file1, FileMode.Open)) using (FileStream fs2 = File.Open(file2, FileMode.Open)) { byte[] one = new byte[BBYTTES_TOREAD]; byte[] teo = new byte[BBYTTES_TOREAD]; while (true) { int len1 = fs1.Read(one, 0, BBYTTES_TOREAD); int len2 = fs2.Read(two, 0, BBYTTES_TOREAD); //字节数字可直接转为ReadOnlySpan if (!((ReadOnlySpan<byte>)one).SequenceEqual((ReadOnlySpan<byte>)two)) return false; if (len1 == 0 || len2 == 0) break; } } }
原文地址:https://www.cnblogs.com/waku/p/11069214.html