| ヘルプでは、[un]checked( チェックすべきコード) のシンタックスしか記載がないが、 [un]checked
	  {チェックすべきコード
 }
 という形式でも通ることを確認した。以下、checked, unchecked のテスト。
 using System;
namespace TestOperators
{
        /// summary
        /// Class1 の概要の説明です。
        /// summary
        class Class1
        {
                static void Main(string[] args)
                {
                        // デフォルト
                        sbyte n1 = SByte.MaxValue;
                        try 
                        {
                                n1++;
                        }
                        catch (Exception e)
                        {
                                Console.WriteLine("Exception: {0}", e);
                        }
                        finally 
                        {
                                Console.WriteLine("Not specified: Exception has not been raised.");
                        }
                        // unchecked の場合
                        sbyte n2 = SByte.MaxValue;
                        try 
                        {
                                n2 = unchecked(n2++);
                        }
                        catch (Exception e)
                        {
                                Console.WriteLine("Exception: {0}", e);
                        }
                        finally 
                        {
                                Console.WriteLine("unchecked: Exception has not been raised.");
                        }
                        // checked() の場合
                        sbyte n3 = SByte.MaxValue;
                        try 
                        {
                                n3 = checked(n3++);
                        }
                        catch (Exception e)
                        {
                                Console.WriteLine("checked: Exception: {0}", e);
                        }
                        // checked{} の場合
                        sbyte n4 = SByte.MaxValue;
                        try 
                        {
                                checked
                                {
                                        n4++;
                                }
                        }
                        catch (Exception e)
                        {
                                Console.WriteLine("checked: Exception: {0}", e);
                                        
                        }
                }
        }
} |