在C#中编译时间错误

时间:2015-02-01 05:42:49

标签: c# compiler-errors

我是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 `>'

2 个答案:

答案 0 :(得分:0)

如果您查看错误,您将识别错误。它会在成员名称中显示一些无效字符。您的会员<key> k__BackingField无效,请替换为k__BackingField

    private int[,] k__BackingField;

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

注意:您的朋友为您提供了来自反汇编程序的代码,因此它会为您提供该错误。请更新上面的代码,它会起作用。

答案 1 :(得分:0)

看起来您正在使用由反编译器生成的编码(.NET Reflector,IL Spy等)。编译错误会告诉您哪些是错误的 - 例如&#39;&lt;&#39;和&#39;&gt;&#39;不允许在变量,成员或类的名称中使用。

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