【问题标题】:How do I Import Encoding class to C# script?如何将编码类导入 C# 脚本?
【发布时间】: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# 脚本?

【问题讨论】:

    标签: c# unity3d


    【解决方案1】:

    你有两个选择:

    1. 在脚本文件顶部导入命名空间:

      using System.Text;
      
    2. 使用完全限定的类名:

      byte[] data = System.Text.Encoding.ASCII.GetBytes(s);
      

    【讨论】:

      猜你喜欢
      • 2012-06-29
      • 2010-11-14
      • 2021-12-30
      • 1970-01-01
      • 1970-01-01
      • 2020-08-10
      • 1970-01-01
      • 2017-08-22
      • 1970-01-01
      相关资源
      最近更新 更多