tags:

views:

89

answers:

3

Hi All,

When I added a 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?

+1  A: 

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).

Fredrik Mörk
@Fredrik, the file created say ßöäüó.cs is fine but in class name it is public class wieredName instead of public class ßöäüó.
Vinay Pandey
@Vinay: ßöäüó looks a LOT like mangled Unicode. I would expect that's UTF-16(LE), and that the real name should be 쎟쎶쎤쎼쎳 - that would be Korean, and no, I can't tell you what that means. (It could be UTF-8, but that expands to ßöäüó, which I *know* is nonsensical).
Michael Madsen
+4  A: 

Read section 9.4.2 from the ECMA Standard for C#

Lazarus
A: 

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.

Cheeso
Did you check to see what the second `.WriteLine(...)` returns?
Matthew Whited
the type name. But I can't see it in my cmd.exe console, which is not unicode. If I Replace that line with a MessageBox, ` System.Windows.Forms.MessageBox.Show(String.Format("type= {0}", this.GetType().Name.ToString()));`, then I see the type name as expected.
Cheeso
@Matthew: You can't go by what that second WriteLine shows in the console. The console settings on your computer are unlikely to be prepared for CJK, because the font used won't have the character and there won't be a font fallback defined, so it can't show the character. You'd get a more accurate view by putting it in a file or in some WinForms control.
Michael Madsen
@Michael: Okay, how about ildasm?
Matthew Whited
While this would work... I would highly not recomend it. You are just asking for trouble later.
Matthew Whited
@Matthew: ildasm doesn't write it correctly if you ask for console output, unless you've changed the codepage to 65001 (UTF-8) and pipe it to a file (I assume file output will work if you pass one of the /UTF8 or /UNICODE switches). The GUI has no problems, and it shouldn't: Unicode identifiers are even allowed in CLS: http://msdn.microsoft.com/en-us/library/12a7a7h3.aspx
Michael Madsen
The UI in ILdasm doesn't play very nice either. I didn't say this didn't work, I just said I wouldn't do it. (Okay, I said I wouldn't recommend it.)
Matthew Whited
@Matthew: The UI doesn't exactly render it nicely (the font it uses isn't ideal), but it's the right characters that are being shown. On pre-Vista, however, the fonts aren't installed by default - I believe you have to enable complex script rendering in the Regional and Language Options applet.
Michael Madsen
I am probably just biased for how long I have been constrained to ASCII. It would work, just seems freaky to me.
Matthew Whited