using System;
using System.Collections.Generic;
using System.Text;namespace ConsoleApplication1
{
    class Program
    {
        
       enum NOTE {Ab,A,As,Cb,C,Cs};
        enum OCCIDENTAL { Forte, Pianissimo };
        enum INSTRUMENT { String, Horn, Piano, Organ };
        enum DURATION { Snote, Enote, Qnote, Hnote, Fnote };
        static void Main(string[] args)
        {
            const int BEATS = 5;
            int [][][] DEM = new int[3][][];
            
            for (int plane = 0; plane < 3; plane++)
                DEM[plane] = new int[4][];
            
            for (int plane = 0; plane < 3; plane++)
                for (int instrument = 0; instrument < 4; instrument++)
                    DEM[plane] = new int[4][];
            DEM[0][0][0] = (int)NOTE.Ab;
            DEM[0][1][0] = (int)NOTE.Cs;
            DEM[0][2][0] = (int)NOTE.Cb;
            DEM[0][3][0] = (int)NOTE.A;            DEM[1][0][0] = (int)OCCIDENTAL.Forte;
            DEM[1][1][0] = (int)OCCIDENTAL.Forte;
            DEM[1][2][0] = (int)OCCIDENTAL.Pianissimo;
            DEM[1][3][0] = (int)OCCIDENTAL.Pianissimo;            DEM[2][0][0] = (int)DURATION.Enote;
            DEM[2][1][0] = (int)DURATION.Fnote;
            DEM[2][2][0] = (int)DURATION.Qnote;
            DEM[2][3][0] = (int)DURATION.Snote;
        }
    }
}
运行时总有异常提示:"尝试读取或写入受保护的内存。这通常指示其他内存已损坏。"

解决方案 »

  1.   

    DEM[0][0][0] = (int)NOTE.Ab;
    当执行到这一语句的时候,就有异常提示
      

  2.   

    using System;
    using System.Collections.Generic;
    using System.Text;namespace ConsoleApplication1
    {
        class Program
        {        enum NOTE { Ab, A, As, Cb, C, Cs };
            enum OCCIDENTAL { Forte, Pianissimo };
            enum INSTRUMENT { String, Horn, Piano, Organ };
            enum DURATION { Snote, Enote, Qnote, Hnote, Fnote };
            static void Main(string[] args)
            {
                const int BEATS = 5;
                int[][][] DEM = new int[3][][];            for (int plane = 0; plane < 3; plane++)
                    DEM[plane] = new int[4][];            for (int plane = 0; plane < 3; plane++)
                    for (int instrument = 0; instrument < 4; instrument++)
                        DEM[plane][instrument] = new int[4];
                DEM[0][0][0] = (int)NOTE.Ab;
                DEM[0][1][0] = (int)NOTE.Cs;
                DEM[0][2][0] = (int)NOTE.Cb;
                DEM[0][3][0] = (int)NOTE.A;            DEM[1][0][0] = (int)OCCIDENTAL.Forte;
                DEM[1][1][0] = (int)OCCIDENTAL.Forte;
                DEM[1][2][0] = (int)OCCIDENTAL.Pianissimo;
                DEM[1][3][0] = (int)OCCIDENTAL.Pianissimo;            DEM[2][0][0] = (int)DURATION.Enote;
                DEM[2][1][0] = (int)DURATION.Fnote;
                DEM[2][2][0] = (int)DURATION.Qnote;
                DEM[2][3][0] = (int)DURATION.Snote;
            }
        }
    }
      

  3.   

                for (int plane = 0; plane < 3; plane++)
                    for (int instrument = 0; instrument < 4; instrument++)
                        DEM[plane] = new int[4][];
    DEM[plane][instrument] = new int[4];