我正在尝试创建一个Caesar密码程序,我正在使用Write方法,但它只会打印出System.Char []。如何打印重新格式化的字符串?我甚至把一切都改正了吗?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Caesar_Cipher
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Read or Write?");
string input1 = Console.ReadLine().ToLower();
if (input1 == "read")
{
}
if (input1 == "write")
{
write();
}
}
static void read()
{
}
public static void write()
{
Console.WriteLine("Write something to translate,");
string value = Console.ReadLine();
Console.WriteLine("How many shifts do you want?");
int shift = int.Parse(Console.ReadLine());
char[] Read = value.ToCharArray();
for (int i = 0; i < Read.Length; i++)
{
int b = i - (Read.Length + shift);
int c = Read.Length - shift;
if (b <= 0)
{
Read[c] = Read[i];
}
else
{
int shift1 = i + shift;
Read[shift1] = Read[i];
}
}
string d = Read.ToString();
Console.WriteLine(d);
}
}
}
答案 0 :(得分:1)
如果您需要将char
的数组转换为string
:
char[] chars = ...;
...
string s = new string(chars);