c# - C#中的编译时错误

This question already has an answer here:
.net Reflector decompiled C# code won't compile

(1个答案)


5年前关闭。




我是C#的新手,不知道下面的代码是什么问题。我的 friend 收到了此代码。基本上,它是一个根据程序对字符串进行加密的程序。请帮我修复它。我将非常感谢。
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 `>'

最佳答案

看起来您正在使用由反编译器(.NET Reflector,IL Spy等)生成的编码。编译错误告诉您什么地方不对-变量,成员或类的名称中不允许使用诸如''之类的字符。

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

https://stackoverflow.com/questions/28259881/

上一篇:c++ - 代码编译错误

下一篇:php - PHP中 undefined index 错误

相关文章:

ios - 'NSInvalidArgumentException',原因 : 'Unable to parse constraint format'

c++ - 更简单的c++模板编译错误输出

python - Python反转计数器: slice indicies error

c# - 在 C# 中是否有从 int 类型安全的枚举转换?

deployment - 在Ubuntu 14.04生产服务器上部署Play Framework 2.3.x(Java样式)

c# - 限制数据查询,只获取最后 1000 行

c# - 如何连接到 C# 中的本地套接字?

c# - Visual Studio 2010 使用第三方库的 Debug 或 Release 版本进行编译,具体取决于我的项目是在编译 Build 还是 Release?

c# - 命名空间级别的枚举 - 仍然需要公开吗?

c# - 更改 ToolStripButton 上的 ToolTipText 延迟时间

相关文章:

java - 出现错误: No enclosing instance of type **** is

c++ - 模板化 BST 方法的返回值问题

java - 未知的Java类错误

android - Android代码抛出错误

oracle - Oracle函数编译错误PLS-00103(遇到符号 “SELECT”…)

c++ - 代码编译错误

exception - 捕获 block 避免编译错误?

c++ - header 多重重新定义

java - 无法编译Java代码

c++ - '' *2之前的解析错误