Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 编码。Unicode未解析_C# - Fatal编程技术网

C# 编码。Unicode未解析

C# 编码。Unicode未解析,c#,C#,我有一个程序,在某个项目中执行一些加密(正常工作),我将它复制到现在正在使用的项目中。但奇怪的是,它无法解析编码。Unicode,Unicode这个词用红色下划线 我得到的错误是: “System.Array”不包含“Unicode”的定义,并且找不到接受“System.Array”类型的第一个参数的扩展方法“Unicode”(是否缺少using指令或程序集引用?) 这在我的一个general.cs类文件中: using System; using System.Collections.Gene

我有一个程序,在某个项目中执行一些加密(正常工作),我将它复制到现在正在使用的项目中。但奇怪的是,它无法解析编码。Unicode,Unicode这个词用红色下划线

我得到的错误是: “System.Array”不包含“Unicode”的定义,并且找不到接受“System.Array”类型的第一个参数的扩展方法“Unicode”(是否缺少using指令或程序集引用?)

这在我的一个general.cs类文件中:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Serialization;

namespace myNamespace
{
    static class myClass
    {
        public static string myProc(string text)
        {
             //...
             byte[] toEncrypt = Encoding.Unicode.GetBytes(text);
             //...
        }
    }
}

奇怪的是,当我将代码复制到我的主窗体时,它没有给出任何错误,因此这与这个类有关?

它代替了
编码.Unicode.GetBytes(text)
在作用域的某个地方(在这个方法或这个类中)有一个名为
编码的数组成员。右键单击
编码
标识符并选择“转到定义…”,您将找到它

重命名该成员或为命名空间添加前缀:

byte[] toEncrypt = System.Text.Encoding.Unicode.GetBytes(text);

Encoding.UTF8.GetBytes(文本)
谢谢CodeCaster,就是这样,我使用了私有静态字符串[]编码;在我的声明中,我完全忘记了那个@m、 罗格尔斯基说,这个建议改变了输出。如果他们想使用Unicode编码(UTF-16),那么改用UTF-8不会得到他们要搜索的结果。@CodeCaster Unicode与UTF-16不同。Unicode是字符集,而UTF-8/UTF-16编码。@m.rogalski通常是这样,但在.NET术语中,“Unicode”相当于“UTF-16”。看,确实存在。