0

我有一段有人给我的 VB.NET 代码,我想知道是否可以将其转换为 C#。我对 VB.NET 几乎一无所知,所以我无法自己转换它。我不知道如何描述它,所以我只是展示它。

Public table = New Object(15) {}
Dim cElse As Char = "█"

Private Sub Form_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
    table(0) = New Char(15) {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "-", "=", "*", "%", " "}
    table(1) = New Char(15) {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P"}
    table(2) = New Char(15) {"Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "(", "!", "?", Chr(147), ":", "."} '147 is open double quotes
    table(3) = New Char(15) {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p"}
    table(4) = New Char(15) {"q", "r", "s", "t", "u", "v", "w", "x", "y", "z", ")", ",", "/", "・", "~", "&"}
    table(5) = New Char(15) {"Á", "À", "Â", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Ï", "Ï", "Ó", "Ò", "Ô", "Ö"}
    table(6) = New Char(15) {"Ú", "Ù", "Û", "Ü", "á", "à", "â", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï"}
    table(7) = New Char(15) {"ó", "ò", "ô", "ö", "ú", "ù", "û", "ü", "Ç", "Ñ", "ç", "ñ", "Œ", "ß", "’", Chr(148)} '148 is close double-quotes
    table(8) = New Char(15) {cElse, Chr(148), cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse}
    table(9) = New Char(15) {cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse}
    table(10) = New Char(15) {"‘", cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse}
    table(11) = New Char(15) {cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse}
    table(12) = New Char(15) {cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse}
    table(13) = New Char(15) {cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse}
    table(14) = New Char(15) {cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse}
    table(15) = New Char(15) {cElse, cElse, cElse, cElse, cElse, cElse, cElse, vbNewLine, cElse, "$", cElse, cElse, cElse, cElse, cElse, "@"} '$ is variable
End Sub

因此,基本上它会创建一个字符表,以便以后用作某种密码。

我仍然是 C# 的业余爱好者,但我想不出一个简单的方法来做到这一点。

如果有人知道,您不必重写整个表格,只需说出要更改的关键字和其他内容即可。

4

5 回答 5

1

简而言之:幸运的是,转换问题主要由可用工具解决。

试试这个很酷的工具:转换为 C#

除了上述工具之外,还有关于将 VB.NET 转换为 C# 的工具的讨论和建议 -将 VB.Net 转换为 C# 的好方法?

于 2013-01-15T04:22:13.670 回答
1
public Object[] table = new Object[16];
private Char cElse = '█';

private void Form_Load(object sender, EventArgs e)
{
    table[0] = new Char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '-', '=', '*', '%', ' ' };
    // ...

    // vbNewLine can be Environment.NewLine, but keep in mind it's not a single Char... its composed of "\r\n" or "\n" depending on the current environment...
    // Chr(147) can be (Char)147 or Convert.ToChar(147) as it's just a Byte representation, and so on...
}
于 2013-01-15T04:26:02.290 回答
0
public object[] table = new object[16];

 char cElse = '█';
 private void Form_Load(object sender, EventArgs e)
{
    table[0] = new char[16] {
        '0',
        '1',
        '2',
        '3',
        '4',
        '5',
        '6',
        '7',
        '8',
        '9',
        '+',
        '-',
        '=',
        '*',
        '%',
        ' '
    };
    table[1] = new char[16] {
        'A',
        'B',
        'C',
        'D',
        'E',
        'F',
        'G',
        'H',
        'I',
        'J',
        'K',
        'L',
        'M',
        'N',
        'O',
        'P'
    };
    table[2] = new char[16] {
        'Q',
        'R',
        'S',
        'T',
        'U',
        'V',
        'W',
        'X',
        'Y',
        'Z',
        '(',
        '!',
        '?',
        (char)147,
        ':',
        '.'
    };
    //147 is open double quotes
    table[3] = new char[16] {
        'a',
        'b',
        'c',
        'd',
        'e',
        'f',
        'g',
        'h',
        'i',
        'j',
        'k',
        'l',
        'm',
        'n',
        'o',
        'p'
    };
    table[4] = new char[16] {
        'q',
        'r',
        's',
        't',
        'u',
        'v',
        'w',
        'x',
        'y',
        'z',
        ')',
        ',',
        '/',
        '・',
        '~',
        '&'
    };
    table[5] = new char[16] {
        'Á',
        'À',
        'Â',
        'Ä',
        'É',
        'È',
        'Ê',
        'Ë',
        'Í',
        'Ì',
        'Ï',
        'Ï',
        'Ó',
        'Ò',
        'Ô',
        'Ö'
    };
    table[6] = new char[16] {
        'Ú',
        'Ù',
        'Û',
        'Ü',
        'á',
        'à',
        'â',
        'ä',
        'é',
        'è',
        'ê',
        'ë',
        'í',
        'ì',
        'î',
        'ï'
    };
    table[7] = new char[16] {
        'ó',
        'ò',
        'ô',
        'ö',
        'ú',
        'ù',
        'û',
        'ü',
        'Ç',
        'Ñ',
        'ç',
        'ñ',
        'Œ',
        'ß',
        '’',
        (char)148
    };
    //148 is close double-quotes
    table[8] = new char[16] {
        cElse,
        (char)148,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse
    };
    table[9] = new char[16] {
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse
    };
    table[10] = new char[16] {
        '\'',
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse
    };
    table[11] = new char[16] {
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse
    };
    table[12] = new char[16] {
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse
    };
    table[13] = new char[16] {
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse
    };
    table[14] = new char[16] {
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse
    };
    table[15] = new char[16] {
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        Environment.Newline,
        cElse,
        '$',
        cElse,
        cElse,
        cElse,
        cElse,
        cElse,
        '@'
    };
    //$ is variable
}
于 2013-01-15T04:27:30.383 回答
0

我唯一不能正确翻译的是vbNewLine因为它返回一个字符串而不是一个字符。我用过\n,希望是对的。

public object[] table = new object[15];
private char cElse = '█';

private void Form_Load(object sender, EventArgs e]) {
    table[0] = new char[] {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '-', '=', '*', '%', ' '};
    table[1] = new char[] {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P'};
    table[2] = new char[] {'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '!', '?', (char)147, ':', '.'}; //147 is open double quotes
    table[3] = new char[] {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p'};
    table[4] = new char[] {'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', ']', ',', '/', '・', '~', '&'};
    table[5] = new char[] {'Á', 'À', 'Â', 'Ä', 'É', 'È', 'Ê', 'Ë', 'Í', 'Ì', 'Ï', 'Ï', 'Ó', 'Ò', 'Ô', 'Ö'};
    table[6] = new char[] {'Ú', 'Ù', 'Û', 'Ü', 'á', 'à', 'â', 'ä', 'é', 'è', 'ê', 'ë', 'í', 'ì', 'î', 'ï'};
    table[7] = new char[] {'ó', 'ò', 'ô', 'ö', 'ú', 'ù', 'û', 'ü', 'Ç', 'Ñ', 'ç', 'ñ', 'Œ', 'ß', '’', (char)148}; //148 is close double-quotes
    table[8] = new char[] {cElse, Chr[148], cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse};
    table[9] = new char[] {cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse};
    table[10] = new char[] {'‘', cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse};
    table[11] = new char[] {cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse};
    table[12] = new char[] {cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse};
    table[13] = new char[] {cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse};
    table[14] = new char[] {cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse};
    table[15] = new char[] {cElse, cElse, cElse, cElse, cElse, cElse, cElse, '\n', cElse, '$', cElse, cElse, cElse, cElse, cElse, '@'}; //$ is variable
}

希望能帮助到你。

于 2013-01-15T04:33:56.830 回答
0
public char[][] table;

private void Form_Load(object sender, EventArgs e)
{
    table = new char[16, 16]
    {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '-', '=', '*', '%', ' '},
    {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P'},
    {'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '(', '!', '?', (char)147, ':', '.'},
    {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p'},
    {'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', ')', ',', '/', '・', '~', '&'},
    {'Á', 'À', 'Â', 'Ä', 'É', 'È', 'Ê', 'Ë', 'Í', 'Ì', 'Ï', 'Ï', 'Ó', 'Ò', 'Ô', 'Ö'},
    {'Ú', 'Ù', 'Û', 'Ü', 'á', 'à', 'â', 'ä', 'é', 'è', 'ê', 'ë', 'í', 'ì', 'î', 'ï'},
    {'ó', 'ò', 'ô', 'ö', 'ú', 'ù', 'û', 'ü', 'Ç', 'Ñ', 'ç', 'ñ', 'Œ', 'ß', '’', (char)148},
    {cElse, (char)148, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse},
    {cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse},
    {'‘', cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse},
    {cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse},
    {cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse},
    {cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse},
    {cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse, cElse},
    {cElse, cElse, cElse, cElse, cElse, cElse, cElse, Environment.Newline, cElse, '$', cElse, cElse, cElse, cElse, cElse, '@'}};
}

抱歉不能帮助 cElse 的定义,因为我看不到实际的角色是什么,但其他一切都应该是好的。

于 2013-01-15T04:34:35.627 回答