Curioddity Number 4: how many strings do I have? [Kit George]
Well its time for another curioddity. This one is pretty fun, there's a couple of good sidesteps involved. The following code is gong to write out 3 lines of code to the Console. Your tasks are to:
1: without running the code, write down what you think will be written out
2: run the code, and see for yourself what was written out
3: figure out, if 1 and 2 don't match, what the heck is going on!
using System.Text;
using System;
class intern
{
static unsafe void ModifyConst() {
string str1 = "Hello";
fixed(char* pstr = str1) {
pstr[0] = 'X';
}
}
static void Main() {
ModifyConst();
StringBuilder sb = new StringBuilder("Hel");
sb.Append("lo");
string str = sb.ToString();
Console.WriteLine(str);
Console.WriteLine("Hello");
switch(str) {
case "Xello":
Console.WriteLine("string is Xello"); break;
case "Hello":
Console.WriteLine("string is Hello"); break;
default:
Console.WriteLine("Not Found"); break;
}
}
}