【问题标题】:Why am I getting System.Char[] output? How do I get the string?为什么我得到 System.Char[] 输出?我如何得到字符串?
【发布时间】:2016-03-16 18:17:12
【问题描述】:

我正在尝试制作一个凯撒密码程序,并且正在研究 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);
        }
    }
}

【问题讨论】:

标签: c# arrays encryption char


【解决方案1】:

如果您需要将chars 的数组转换为string

char[] chars = ...;
...

string s = new string(chars);

【讨论】:

    猜你喜欢
    • 2015-12-29
    • 2013-08-17
    • 2013-07-06
    • 1970-01-01
    • 2023-02-21
    • 2017-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多