C#中的编译时错误

Compile time error in C#

我是 C# 的新手,不知道下面的代码有什么问题。我的朋友得到了这个代码。基本上,它是一个根据程序加密字符串的程序。请帮我解决它。我将不胜感激。

using System;
using System.Linq;
using System.Runtime.CompilerServices;

class Class1
    {

        // error lies in these 10 lines mainly.

        private int[,] <key> k__BackingField;

        public int[,] key
        {
            get
            {
                return <key>k__BackingField;
            }
            set
            {
                <key>k__BackingField = value;
            }
        }

        public Class1()
        {
        }

        public string CreatetheCipher(string plainText, int rowsize, int colsize)
        {
            char[] chArr = plainText.ToCharArray();
            int[,] iArr = new int[3, 3];
            int i1 = 0, i2 = 0;
            int i3 = Enumerable.Count<char>(chArr);
            for (int i4 = 0; i4 < rowsize; i4++)
            {
                for (int i5 = 0; i5 < colsize; i5++)
                {
                    if (i2 < i3)
                    {
                        if (Char.IsUpper(chArr[i2]))
                            i1 = Convert.ToInt32(chArr[i2] - 65);
                        iArr[i4, i5] = i1;
                        i2++;
                    }
                    else
                    {
                        iArr[i4, i5] = 0;
                    }
                }
            }
            int i6 = 0;
            char[,] chArr1 = new char[3, 3];
            for (int i7 = 0; i7 < rowsize; i7++)
            {
                for (int i8 = 0; i8 < colsize; i8++)
                {
                    for (int i9 = 0; i9 < 3; i9++)
                    {
                        i6 += key[i7, i9] * iArr[i9, i8];
                    }
                    char ch = (ushort)i6;
                    chArr1[i7, i8] = ch;
                    i6 = 0;
                }
            }
            string s = String.Empty;
            for (int i10 = 0; i10 < 3; i10++)
            {
                for (int i11 = 0; i11 < 3; i11++)
                {
                    s = String.Concat(s, chArr1[i10, i11]);
                }
            }
            return s;
        }

} // class Class1

public public class Test
{
    public static void Main()
    {
        Class1 a = new Class1("SWEETLORD-OlUXOmMhEiQO");
        System.Console.WriteLine(a.CreateTheCypher());
    }
}

这是编译器错误信息

prog.cs(9,24): error CS1519: Unexpected symbol `<' in class, struct, or interface member declaration
prog.cs(9,28): error CS1519: Unexpected symbol `>' in class, struct, or interface member declaration
prog.cs(9,45): error CS1519: Unexpected symbol `;' in class, struct, or interface member declaration
prog.cs(15,23): error CS1525: Unexpected symbol `<'
prog.cs(15,27): error CS1525: Unexpected symbol `>'
prog.cs(19,16): error CS1525: Unexpected symbol `<'
prog.cs(19,20): error CS1525: Unexpected symbol `>'

如果您查看错误,您就会发现错误。它建议在成员名称中使用一些无效字符。您的成员 <key> k__BackingField 无效,请替换为 k__BackingField

    private int[,] k__BackingField;

    public int[,] key
    {
        get
        {
            return k__BackingField;
        }
        set
        {
            k__BackingField = value;
        }
    }

注意:您的朋友从反汇编程序中为您提供了代码,所以它给了您那个错误。请更新上面的代码,它将起作用。

您似乎正在使用由反编译器(.NET Reflector、IL Spy 等)生成的代码。编译错误会告诉您哪里出了问题 - 变量名称、成员名称或 类.

中不允许使用诸如“<”和“>”之类的字符

<key>k__BackingField 重命名为 key_k__BackingField 或类似的名称将至少消除您上面列出的错误。