using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication21
{
    class MyException throws IndexOutOfRangeException
    {
        public int[] myArray=new int[4]{1,2,3,4};
    }
    class TestException
    {
        static void Main()
        {
            MyException me=new MyException();
            try
            {
                me.myArray[5]=5;
            }
            catch(IndexOutOfRangeException ex)
            {
                Console.WriteLine("出现错误了!");
                Console.WriteLine(ex.Data.ToString());
            }
            Console.WriteLine();
        }
    }
}
书上的代码,红色的字给出了红色的波浪线,哪里出问题了?

解决方案 »

  1.   

    throws IndexOutOfRangeException ,C# 没有这语法吧,去掉就行了
      

  2.   

    throws 这貌似是java语法……
      

  3.   

    看错了,throws 换成 :(冒号)
      

  4.   

    1.throws IndexOutOfRangeException删掉
    2.IndexOutOfRangeException不能继承,楼上都在卖萌吗
      

  5.   

    对的,是不能继承IndexOutOfRangeException类的
      

  6.   

    NET中是没有throws的,倒是有throw
      

  7.   


    惭愧,被throws吸引了注意力没注意能不能被继承的问题