當前位置:成語大全網 - 新華字典 - 急求把壹段C++代碼翻譯為C#代碼

急求把壹段C++代碼翻譯為C#代碼

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.IO;

namespace ConsoleApplication1

{

class Program

{

static int Main(string[] args)

{

StreamReader sr = new StreamReader("zidian.txt");

int i = 0;

Dictionary<int, string> zidian = new Dictionary<int, string>();

string s;

while (!sr.EndOfStream)

{

s = sr.ReadLine();

zidian.Add(i, s);

}

string ci;

Console.WriteLine("輸入要查的單詞:");

ci=Console.ReadLine();

search(ci, zidian);

bool c = true;

while (c)

{

Console.WriteLine("想繼續麽?y/n");

System.ConsoleKeyInfo yorn;

yorn = Console.ReadKey();

if (yorn.KeyChar.Equals('y'))

{

string cj;

Console.WriteLine("輸入要查的單詞:");

cj = Console.ReadLine();

search(cj, zidian);

}

if (yorn.KeyChar.Equals('n'))

{

c = false;

}

}

return 0;

}

static string search(string c, Dictionary<int, string> b)

{

string str=null;

Dictionary<int, string>.Enumerator iter= b.GetEnumerator();

while (iter.MoveNext())

{

str = iter.Current.Value;

if (str.Equals(c))

{

Console.WriteLine(str);

break;

}

}

return str;

}

}

}