0

2 つのファイルの比較について助けが必要です。2つの違いを印刷することはできますが、間違っている場合に2つの同じものを印刷する方法を理解できません。誰でも私を助けることができますか?前もって感謝します!

    private void button2_Click(object sender, EventArgs e)
    {
        try
        {
            //Reads files line by line
            var fileOld = File.ReadLines(Old);
            var fileNew = File.ReadLines(New);                              //Ignores cases in files
            IEnumerable<String> OldTxt = fileOld.Except(fileNew, StringComparer.OrdinalIgnoreCase);
            IEnumerable<String> NewTxt = fileNew.Except(fileOld, StringComparer.OrdinalIgnoreCase);

            FileCompare compare = new FileCompare();

            bool areSame = OldTxt.SequenceEqual(NewTxt);

            if (areSame == true)
            {
                MessageBox.Show("They match!");
            }
            else if(areSame == false)
            {
                // Find the set difference between the two files.  
                // Print to Not Equal.txt
                var difFromNew = (from file in OldTxt
                                  select file).Except(NewTxt);

                using (var file = new StreamWriter(NotEqual))
                {
                    foreach (var notEq in difFromNew)
                    {
                        file.WriteLine(notEq.ToString() + "\n", true);
                    }
                }

                MessageBox.Show("They are not the same! Please look at 'Not Equal.txt' to see the difference. Look at 'Equal.txt' to see what is the same at this time.");
            }

        }
        catch
        {
            MessageBox.Show("'NewConvert.txt' or 'OldConvert.txt' files does not exist.");
        }

    }
4

1 に答える 1