コード例 #1
0
ファイル: program.cs プロジェクト: zhimaqiao51/docs
        private static void ViewInHex(Object fileName)
        {
            _workerStarted = true;
            byte[] bytes;
            using (MyFileReader reader = new MyFileReader((String)fileName))
            {
                bytes = reader.ReadContents(20);
            }  // Using block calls Dispose() for us here.

            if (_printToConsole)
            {
                // Print up to 20 bytes.
                int printNBytes = Math.Min(20, bytes.Length);
                Console.WriteLine("First {0} bytes of {1} in hex", printNBytes, fileName);
                for (int i = 0; i < printNBytes; i++)
                {
                    Console.Write("{0:x} ", bytes[i]);
                }
                Console.WriteLine();
            }
        }
コード例 #2
0
        private static void ViewInHex(object fileName)
        {
            _workerStarted = true;
            byte[] bytes;

            using (MyFileReader reader = new MyFileReader(fileName.ToString()))
            {
                bytes = reader.ReadContents(20);
            }

            if (_printToConsole)
            {
                //Print up to 20 bytes.
                //最多打印20个字节
                int printNBytes = Math.Min(20, bytes.Length);
                Console.WriteLine($"First {printNBytes} bytes of {fileName} in hex");
                for (int i = 0; i < printNBytes; i++)
                {
                    Console.WriteLine($"{bytes[i]:x}");
                }
                Console.WriteLine();
            }
        }