将两行从VB.NET转换为C#

ian*_*ley 1 c# vb.net

我似乎无法正确地将以下内容从VB.NET转换为C# -

iKeyChar = Asc(mid(g_Key, i, 1))
iStringChar = Asc(mid(strCryptThis,i,1))
Run Code Online (Sandbox Code Playgroud)

这是我转换的C#代码,它似乎没有输出等价值 -

iKeyChar = Convert.ToInt32(g_Key.Substring(i, 1));
iStringChar = Convert.ToInt32(strCryptThis.Substring(i, 1));
Run Code Online (Sandbox Code Playgroud)

任何帮助是极大的赞赏!

Sys*_*own 8

那是因为Mid基于Substring零,而基于零.试试这种方式:

iKeyChar = (int)Convert.ToChar(g_Key.Substring(i-1, 1));
iStringChar = (int)Convert.ToChar(strCryptThis.Substring(i-1, 1));
Run Code Online (Sandbox Code Playgroud)