次のコードを検討してください。
using System;
using System.Runtime.InteropServices;
namespace Demo
{
    class Program
    {
        static void Main(string[] args)
        {
            const string test = "ABCDEF"; // Strings are immutable, right?
            char[] chars = new StringToChar{str=test}.chr;
            chars[0] = 'X';
            // On an x32 release or debug build or on an x64 debug build, 
            // the following prints "XBCDEF".
            // On an x64 release build, it prints "ABXDEF".
            // In both cases, we have changed the contents of 'test' without using
            // any 'unsafe' code...
            Console.WriteLine(test);
        }
    }
    [StructLayout(LayoutKind.Explicit)]
    public struct StringToChar
    {
        [FieldOffset(0)]
        public string str;
        [FieldOffset(0)]
        public char[] chr;
    }
}
このコードを実行することで、例外が発生することなく文字列の内容を変更できます。そのために安全でないコードを宣言する必要はありませんでした。このコードは明らかに非常に危険です!
私の質問は単純にこれです:あなたは例外が上記のコードによってスローされるべきだと思いますか?
[編集1:他の人が私のためにこれを試した、そして何人かの人が異なる結果を得ることに注意してください-私がしていることの厄介さを考えるとそれほど驚くことではありません...;)]
[編集2:Windows 7Ultimate64ビットでVisualStudio2010を使用していることに注意してください]
[EDIT3:テスト文字列をconstにしました。これは、さらに危険なものにするためです!]