segunda-feira, 12 de agosto de 2019

C# - Inicializando ArrayList com caracteres

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

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.DarkBlue;
                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 ( ) {
        ArrayList arrayList = new ArrayList ( ) {
                   'A','B','C','D','E',
                   'F','G','H','I','J',
                   'L','M','N','O','P',
                   'Q','R','S','T','U',
                   'V','X','Z','Y','K'};
        int i;
        //Posiciona os textos no console
        Console.SetCursorPosition ( 20, 4 );
        Console.ForegroundColor = ConsoleColor.Blue;
        for ( i = 0; i < arrayList.Count; i++ ) {
            if ( i % 5 == 0 )
                Console.Write ( "\n\t\t\t" );
            Console.Write ( arrayList [ i ] + " " );
        }
        Arr array = new Arr ( );
        array.Barra ( 2, 20 );
        Console.ReadKey ( );
    }
    /*============================================================*/
    public static void Main ( ) {
        Console.Title = ( "C# - ARRAYLIST INICIALIZANDO COM CARACTERES" );
        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 CARACTERES" );
        array.Informe ( );
        array.Ini_Array ( );
        //Segura a execução do programa
        Console.ReadKey ( );
    }
}
/*============================================================*/
 


 

Nenhum comentário:

Postar um comentário