【发布时间】:2015-12-25 04:32:53
【问题描述】:
static byte[] GetData()
{
string s = "this is some text";
byte[] data = Encoding.ASCII.GetBytes(s);
return data;
}
我发现这段代码很有用,但我遇到了 GetData() 方法的问题。编译代码后,我收到消息说..
错误:当前上下文中不存在名称“编码”。
那么如何将编码类导入 C# 脚本?
【问题讨论】:
static byte[] GetData()
{
string s = "this is some text";
byte[] data = Encoding.ASCII.GetBytes(s);
return data;
}
我发现这段代码很有用,但我遇到了 GetData() 方法的问题。编译代码后,我收到消息说..
错误:当前上下文中不存在名称“编码”。
那么如何将编码类导入 C# 脚本?
【问题讨论】:
你有两个选择:
在脚本文件顶部导入命名空间:
using System.Text;
使用完全限定的类名:
byte[] data = System.Text.Encoding.ASCII.GetBytes(s);
【讨论】: