开发者

Non-Ascii characters not supported by .net?

开发者 https://www.devze.com 2022-12-26 01:01 出处:网络
When I added a开发者_如何学JAVA class with non-Ascii caharacters in the class name, it removed the non-Ascii from class name and when added directly to class it complains of non-Ascii characters.

When I added a开发者_如何学JAVA class with non-Ascii caharacters in the class name, it removed the non-Ascii from class name and when added directly to class it complains of non-Ascii characters.

Are Non-ASCII characters not supported in class name and variable name?


Read section 9.4.2 from the ECMA Standard for C#


You probably need to save the file with an encoding that supports the characters that you want to have in your class name:

  • Click File -> Save as
  • Click the little arrow by the save button, and select "Save with encoding..."

However, it feels like begging for trouble to have class names that requires an extended encoding (but it's only a feeling I get; don't have any experience with it, really).


This compiles and runs for me

public class 嗨世界
{
    public 嗨世界() {}

    public void Run()
    {
        System.Console.WriteLine("Hello, Unicode world.");
        System.Console.WriteLine("type= {0}", this.GetType().Name.ToString());
    }

    public static void Main(string[] args)
    {
        try
        {
            new 嗨世界()
                .Run();
        }
        catch (System.Exception exc1)
        {
            Console.WriteLine("Exception: {0}", exc1.ToString());
        }
    }
}

ps: I have no idea what those characters mean.

0

精彩评论

暂无评论...
验证码 换一张
取 消