Skip to content

Instantly share code, notes, and snippets.

Created November 26, 2014 13:43
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/c59a113ce5da0913e1f9 to your computer and use it in GitHub Desktop.
Save anonymous/c59a113ce5da0913e1f9 to your computer and use it in GitHub Desktop.
// What's the output of this code, and how confident are you?
// What might affect the result?
class Test
{
static void Main()
{
string stringx = "a";
string\u180ex = "b";
System.Console.WriteLine(stringx);
}
}
@debugmodedotnet
Copy link

a

@ahmetabdi
Copy link

b, 100%.

@GitHubber10
Copy link

It should be "b", because the Mongolian vowel separator is a combining character.
So I guess the file's encoding might affect the result?

@jeroenlandheer
Copy link

You should get "b" in the output... I wonder if an Mongolian vowel separator is legal according to the specs though...

EDIT: After some digging: The Mvs is not in the Unicode class 'Zs' which is determined to be a white space according to the C# Language Spec (Grammer section 1.2), it is in the class 'Cf' which is the class described as 'Other, Format'... Since it is not a white space... it is removed.

@aydjay
Copy link

aydjay commented Nov 26, 2014

To my eyes it doesn't look like it compiles!

@jskeet
Copy link

jskeet commented Nov 26, 2014

I'm still trying to find a machine that's sufficiently out of date to make it print "a". That should be a bit of a hint :)

(But both outputs are potentially valid. Arguably, only "a" strictly complies with the C# 5 specification, I believe...)

@jskeet
Copy link

jskeet commented Nov 27, 2014

Ah - made more progress. It should either compile with a result of "b", or it should not compile. The Mono compiler (at least the version I'm using) has a bug where even "string\u0020x" works, but that fails to compile with csc.exe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment