using System.Collections.Generic;
using System.Text;namespace myHomeworkTest30
{
class Program
{
static void Main(string[] args)
{
Emp emp = new Emp();//定義壹個對象.自動調用其構造方法,接收字符串並轉化為字符數組
int len=emp.show();//調用實現加密字符串的方法,並返回字符數組的長度
for (int i = 0; i < len-1; i++)
{
Console.Write(emp[i]);//通過索引器進行輸出
}
Console.ReadLine();
}
}
public class Emp
{
public string str = "";//接收字符串
public char[] arr;//字符數組來用存放把字符串轉後成字符
public char first;//加密後的字符串中的第壹個字符
public Emp()
{
Console.WriteLine("請輸入壹個要加密的字符串:");
str = Console.ReadLine();//接收
arr=str.ToCharArray();//字符串.ToCharArray()把字符串轉化為字符數組
}
public int show()//實現加密的方法
{
first=arr[arr.Length - 1];//把原字符數組中的最後壹個字符拿出來作為加密後的第壹個字符
Console.WriteLine("加密後的字符串為:");
Console.Write(first);//輸出加密後的第壹個字符
for (int i = 0; i < arr.Length; i++)
{
arr[i] = (char)(arr[i] + 3);//對於其它的字符進行加密,+3
}
return arr.Length;//返回字符數組的長度
}
//定義壹個索引器
public char this[int index]
{
get
{
return arr[index];
}
set
{
arr[index] = value;
}
}
}
}