读入外部文件然后在凯撒移位后显示

Read In External File Then Display After Caesar Shift

Blockquote

我已经成功地让我的代码从外部文件中读取文本并显示它。我也有一个简单的凯撒转变的代码。我只是不知道如何让我的代码读取文件然后执行凯撒移位并在凯撒移位后显示输出,有人可以帮忙吗?这是我的代码:

using System;
using System.IO; 

class Shift
{
    public static void Main(string [] args)

    {

        //Read in code to shift from text file.
        string file = @"txt"; //I have a file linked here
        string text = File.ReadAllText(file);
        //Show original unshifted code. 
        System.Console.WriteLine("Original text reads: \n\n{0}", text);

        //Show text after shift. 
        Console.WriteLine("The shifted code is: \n\n{1}", b);

    //Start Caesar Shift code as a seperate method.  
    }
    public static string Caesar(string value, int shift)
    {  
    char[] buffer = value.ToCharArray();
    for (int i = 0; i < buffer.Length; i++)
    {
        char letter = buffer[i];
        letter = (char)(letter + shift);
        if (letter > 'z')
        {
        letter = (char)(letter - 26);
        }
        else if (letter < 'a')
        {
        letter = (char)(letter + 26);
        }
        // Store shift. 
        buffer[i] = letter;
    }
    return new string(buffer);
  }
  //Add number to shift text. 
   public static void Second()
    {
    string a = text;
    string b = Caesar(a, 18); 
    }
}

你快到了。查看下面代码段中的最后一个 Console.WriteLine。

public static void Main(string[] args)
{
    //Read in code to shift from text file.
    var file = @"txt"; //I have a file linked here
    var text = File.ReadAllText(file);
    //Show original unshifted code. 
    Console.WriteLine("Original text reads: \n\n{0}", text);

    //Show text after shift. 
    Console.WriteLine("The shifted code is: \n\n{0}", Caesar(text, 18));
}