如下代码,一眼可以看出来输出结果显然应该是-1

static void Main()
{
int intIndex = -1;
string strTest = "xxxxx";
string strMaru = "〇";
intIndex = strTest.IndexOf(strMaru);
Console.WriteLine(intIndex);
Console.Read();
}

然尔今天写代码时候遇到这个诡异的问题,不管如何变换,IndexOf("〇")结果总是0,也就是匹配任意字符串的开始部分.甚是奇怪,至今不明白为什么会是这个结果-_-!
通过IL反汇编得到如下结果:
.method private hidebysig static void Main() cil managed
{
.entrypoint
// 代码大小 37 (0x25)
.maxstack 2
.locals init ([0] int32 intIndex,
[1] string strTest,
[2] string strMaru)
IL_0000: nop
IL_0001: ldc.i4.m1
IL_0002: stloc.0
IL_0003: ldstr "xxxxx"
IL_0008: stloc.1
IL_0009: ldstr bytearray (07 30 ) // .0
IL_000e: stloc.2
IL_000f: ldloc.1
IL_0010: ldloc.2
IL_0011: callvirt instance int32 [mscorlib]System.String::IndexOf(string)
IL_0016: stloc.0
IL_0017: ldloc.0
IL_0018: call void [mscorlib]System.Console::WriteLine(int32)
IL_001d: nop
IL_001e: call int32 [mscorlib]System.Console::Read()
IL_0023: pop
IL_0024: ret
} // end of method Program::Main

即"〇"对应值是bytearray (07 30 ),初步猜想,此字符应该是特殊字符,在.net编译时做了特殊处理.具体回头查查资料先...
说明一下:"〇"是日文中常用字符,可以通过日文输入法输入maru(まる)得到

Back