using System; using System.Diagnostics.Contracts; public class Test { unsafe static char* MatchChars(char* p, char* p2) { Console.WriteLine("MatchChars:"); if (*p2 == '\0') { Console.WriteLine("return null; (1)"); return null; } for (; (*p2 != '\0'); p++, p2++) { if (*p != *p2) { Console.WriteLine("return null; (2)"); return null; } } Console.WriteLine("return p;"); return p; } unsafe static int* MatchInts(int* p, int* p2) { Console.WriteLine("MatchInts:"); if (*p2 == '\0') { Console.WriteLine("return null; (1)"); return null; } for (; (*p2 != 0); p++, p2++) { if (*p != *p2) { Console.WriteLine("return null; (2)"); return null; } } Console.WriteLine("return p;"); return p; } unsafe public static void Main() { fixed (char* p1 = new char[] { '.', '5' } ) { fixed (char* p2 = ".") { MatchChars(p1, p2); } } Console.WriteLine("------------------"); fixed (int* p1 = new int[] { 5, 10, 15, 20 } ) { fixed (int* p2 = new int [] { 5 } ) { MatchInts(p1, p2); } } Console.WriteLine("------------------"); } }