/// <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

相关文章:

  • 2022-12-23
  • 2021-11-28
  • 2021-11-18
  • 2022-12-23
  • 2021-11-28
  • 2022-01-11
  • 2022-02-07
  • 2021-07-01
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
相关资源
相似解决方案