Esempio n. 1
0
    public Chapter1()
    {
        FailSoftArray fs = new FailSoftArray(5);

        // Use Error property.
        for (int i = 0; i < fs.Length + 1; i++)
        {
            fs[i] = i * 10;
            if (fs.Error)
                Console.WriteLine("Error with index " + i);
        }

        Console.WriteLine("\nTest Struct");

        TstIndex strct = new TstIndex(10);

        for (int i = 0; i < 10; i++)
        {
            strct[i] = i;
        }

        for (int i = 0; i < 10; i++)
        {
            Console.WriteLine(strct[i]);
        }
    }
 static void Main(string[] args)
 {
     FailSoftArray fs = new FailSoftArray(5);
     int x;
     // Show quiet failures.
     Console.WriteLine("Fail quietly.");
     for (int i = 0; i < (fs.Length * 2); i++)
         fs[i] = i * 10;
     for (int i = 0; i < (fs.Length * 2); i++)
     {
         x = fs[i];
         if (x != -1) Console.Write(x + " ");
     }
     Console.WriteLine();
     // Now, display failures.
     Console.WriteLine("\nFail with error reports.");
     for (int i = 0; i < (fs.Length * 2); i++)
     {
         fs[i] = i * 10;
         if (fs.ErrFlag)
             Console.WriteLine("fs[" + i + "] out-of-bounds");
     }
     for (int i = 0; i < (fs.Length * 2); i++)
     {
         x = fs[i];
         if (!fs.ErrFlag) Console.Write(x + " ");
         else
             Console.WriteLine("fs[" + i + "] out-of-bounds");
     }
     Console.ReadLine();
 }
Esempio n. 3
0
    public static void Main()
    {
        FailSoftArray fs = new FailSoftArray(5);

        // Используем свойство Error.
        for (int i = 0; i < fs.Length + 1; i++)
        {
            fs[i] = i * 10;
            if (fs.Error)
            {
                Console.WriteLine("Ошибка в индексе " + i);
            }
        }
    }
Esempio n. 4
0
    static void Main()
    {
        FailSoftArray fs = new FailSoftArray(5);

        // Use Error property.
        for (int i = 0; i < fs.Length + 1; i++)
        {
            fs[i] = i * 10;
            if (fs.Error)
            {
                Console.WriteLine("Error with index " + i);
            }
        }
    }
    public static void Main()
    {
        FailSoftArray fs = new FailSoftArray(5);

        // Помещаем в массив fs несколько значений.
        for (int i = 0; i < fs.Length; i++)
        {
            fs[i] = i;
        }
        // Теперь используем в качестве индекса
        // int- и double-значения.
        Console.WriteLine("fs[1]: " + fs[1]);
        Console.WriteLine("fs[2]: " + fs[2]);
        Console.WriteLine("fs[1.1]: " + fs[1.1]);
        Console.WriteLine("fs[1.6]: " + fs[1.6]);
    }
    static void Main()
    {
        FailSoftArray fs = new FailSoftArray(5);

        // Put some values in fs.
        for (int i = 0; i < fs.Length; i++)
        {
            fs[i] = i;
        }
        // Now index with ints and doubles.
        Console.WriteLine("fs[1]: " + fs[1]);

        Console.WriteLine("fs[2]: " + fs[2]);
        Console.WriteLine("fs[1.1]: " + fs[1.1]);
        Console.WriteLine("fs[1.6]: " + fs[1.6]);
    }
Esempio n. 7
0
    public static void Main()
    {
        FailSoftArray fs = new FailSoftArray(5);
        int           x;

        // Вот как выглядит "мягкая посадка" при ошибках.
        Console.WriteLine("Мягкое приземление.");
        for (int i = 0; i < (fs.Length * 2); i++)
        {
            fs[i] = i * 10;
        }
        for (int i = 0; i < (fs.Length * 2); i++)
        {
            x = fs[i];
            if (x != -1)
            {
                Console.Write(x + " ");
            }
        }
        Console.WriteLine();
        // Теперь генерируем некорректный доступ.
        Console.WriteLine(
            "\nРабота с уведомлением об ошибках.");
        for (int i = 0; i < (fs.Length * 2); i++)
        {
            fs[i] = i * 10;
            if (fs.errflag)
            {
                Console.WriteLine("fs[" + i + "] вне границ");
            }
        }
        for (int i = 0; i < (fs.Length * 2); i++)
        {
            x = fs[i];
            if (!fs.errflag)
            {
                Console.Write(x + " ");
            }
            else
            {
                Console.WriteLine("fs[" + i + "] вне границ");
            }
        }
    }
Esempio n. 8
0
        static void Main()
        {
            FailSoftArray fs = new FailSoftArray(5);
            int           x;

            for (int i = 0; i < (fs.Length * 2); i++)
            {
                fs[i] = i * 10;
            }
            for (int i = 0; i < (fs.Length * 2); i++)
            {
                x = fs[i];
                if (x != 1)
                {
                    Console.WriteLine(x + " ");
                }
            }
            Console.WriteLine();

            Console.WriteLine("ShowError");
            for (int i = 0; i < (fs.Length * 2); i++)
            {
                fs[i] = i * 10;
                if (fs.ErrFlag)
                {
                    Console.WriteLine("fs[{0}] out-of-bounds", i);
                }
            }
            for (int i = 0; i < (fs.Length * 2); i++)
            {
                x = fs[i];
                if (x != 1)
                {
                    Console.WriteLine(x + " ");
                }
                if (fs.ErrFlag)
                {
                    Console.WriteLine("fs[{0}] out-of-bounds", i);
                }
            }
        }
Esempio n. 9
0
    static void Main()
    {
        FailSoftArray fs = new FailSoftArray(5);
        int           x;

        // Can read Length.
        for (int i = 0; i < fs.Length; i++)
        {
            fs[i] = i * 10;
        }
        for (int i = 0; i < fs.Length; i++)
        {
            x = fs[i];
            if (x != -1)
            {
                Console.Write(x + " ");
            }
        }
        Console.WriteLine();
        // fs.Length = 10; // Error, illegal!
    }
    public static void Main()
    {
        FailSoftArray fs = new FailSoftArray(5);
        int           x;

        // Свойство Length можно считывать.
        for (int i = 0; i < fs.Length; i++)
        {
            fs[i] = i * 10;
        }
        for (int i = 0; i < fs.Length; i++)
        {
            x = fs[i];
            if (x != -1)
            {
                Console.Write(x + " ");
            }
        }
        Console.WriteLine();
        // fs.Length = 10; // Ошибка, запись запрещена!
    }
Esempio n. 11
0
 static void Main(string[] args)
 {
 FailSoftArray fs = new FailSoftArray();
 }