segunda-feira, 12 de agosto de 2019

C# - Inicializando ArrayList com inteiros

Aqui está um exemplo de inicialização de um ArrayList com inteiros.

Veja abaixo uma imagem do programa em execução:



Veja abaixo o código do programa:



using System;
using System.Collections;

class Arr {
    /*============================================================*/
    void Barra ( int lin, int col ) {
        int i, j;
        for ( i = 0; i < lin; i++ )
            for ( j = 0; j < col; j++ ) {
                Console.SetCursorPosition ( i, j );
                Console.BackgroundColor = ConsoleColor.DarkRed;
                Console.Write ( " " );
            }
    }
    /*============================================================*/
    void Informe ( ) {
        Console.BackgroundColor = ConsoleColor.White;
        Console.SetCursorPosition ( 20, 16 );
        Console.ForegroundColor = ConsoleColor.Red;
        Console.Write ( "Por: " );
        Console.SetCursorPosition ( 25, 16 );
        Console.ForegroundColor = ConsoleColor.Blue;
        Console.Write ( "Samuel Lima" );
        Console.SetCursorPosition ( 20, 17 );
        Console.ForegroundColor = ConsoleColor.Black;
        Console.Write ( "sa_sp10@hotmail.com" );
        Console.SetCursorPosition ( 30, 19 );
        Console.ForegroundColor = ConsoleColor.Red;
        Console.Write ( "MUITO OBRIGADO" );
    }
    /*============================================================*/
    void Moldura ( int tam_lin_ini, int tam_lin_fim, int tam_ini_col,
        int tam_fim_col ) {
        int i, c;
        for ( i = tam_lin_ini; i < tam_lin_fim; i++ ) {
            for ( c = tam_ini_col; c < tam_fim_col; c++ ) {
                Console.SetCursorPosition ( c, i );
                Console.BackgroundColor = ConsoleColor.White;
                Console.Write ( " " );
            }
        }
    }
    /*============================================================*/
    void Ini_Array ( ) {
        IList arrayList = new ArrayList ( ) {
             1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ,
            11, 12, 13, 14, 15, 16, 17, 18, 19, 20 ,
            21, 22, 23, 24, 25, 26, 27, 28, 29, 30 ,
            31, 32, 33, 34, 35, 36, 37, 38, 39, 40 ,
            41, 42, 43, 44, 45, 46, 47, 48, 49, 50 ,
            51, 52, 53, 54, 55, 56, 57, 58, 59, 60 ,
            61, 62, 63, 64, 65, 66, 67, 68, 69, 70 ,
            71, 72, 73, 74, 75, 76, 77, 78, 79, 80 ,
            81, 82, 83, 84, 85, 86, 87, 88, 89, 90 ,
            91, 92, 93, 94, 95, 96, 97, 98, 99, 100};
        int i;
        //Posiciona os textos no console
        Console.SetCursorPosition ( 20, 4 );
        Console.ForegroundColor = ConsoleColor.Black;
        for ( i = 0; i < arrayList.Count; i++ ) {
            if ( i % 10 == 0 )
                Console.Write ( "\n\t\t" );
            if ( i >= 0 && i < 9 )
                Console.Write ( "0" );
            Console.Write ( arrayList [ i ] + " " );
        }
        Arr array = new Arr ( );
        array.Barra ( 2, 20 );
        Console.ReadKey ( );
    }
    /*============================================================*/
    public static void Main ( ) {
        Console.Title = ( "C# - ARRAYLIST INICIALIZANDO COM INTEIROS" );
        Arr array = new Arr ( );
        array.Moldura ( 1, 20, 2, 68 );
        Console.SetCursorPosition ( 15, 2 );
        Console.BackgroundColor = ConsoleColor.White;
        Console.ForegroundColor = ConsoleColor.Red;
        Console.Write ( "C# - ARRAYLIST INICIALIZANDO COM INTEIROS" );
        array.Informe ( );
        array.Ini_Array ( );
        //Segura a execução do programa
        Console.ReadKey ( );
    }
}
/*============================================================*/

Nenhum comentário:

Postar um comentário