小孩脸上有圆形白斑:C#的加密中如果将字符连接成字符串?

来源:百度文库 编辑:高考问答 时间:2024/05/04 05:49:08
using System;
using System.Text;

class class1
{

static void Main()
{

Console.WriteLine("enter the string");
string num = Console.ReadLine();
StringBuilder sb = new StringBuilder();
foreach (char a in num)
{
string s2 = null;
int s;
s = (int)a + 3;
char s1 = (char)s;
string s3 = Convert.ToString(s1);

s2 = s2 + s3;
Console.WriteLine(“the result is:{0}”s2);
}
}
}

这个程序是将输入的字符串加3后输出,即输入“1a”输出“4d”。下现在的问题是结果是分开输出的
enter the string:
1a
the result is:
4
d
如果把它拼起来后再输出?
变成
the result is:
4d

static void Main()
{

Console.WriteLine("enter the string");
string num = Console.ReadLine();
StringBuilder sb = new StringBuilder();
string s2 = null; // 这行放到循环外面来
foreach (char a in num)
{
int s;
s = (int)a + 3;
char s1 = (char)s;
string s3 = Convert.ToString(s1);

s2 = s2 + s3;
}
Console.WriteLine(“the result is:{0}”s2); // 这行也是。
}
}