segunda-feira, 17 de dezembro de 2018

C# - contador com loop while

Este array de inteiros tem suas posições preenchida 
automaticamente por um contador com laço do while,
o código é didático e totalmente indicado aos 
iniciantes em C#.




//C# contador com loop while
using System;
using System.Drawing;
using System.Windows.Forms;

namespace keypress {
    public partial class Form1 : Form {
        public String str;
        /*============================================================*/
        public void Ini_Array ( ) {
            int [ ] arr = new int [ 100 ];
            int i = 0;
            do {
                arr [ i ] = i;
                if ( arr [ i ] % 10 == 0 ) {
                    str += ( "\n" );
                }
                if ( i >= 0 && i <= 9 )
                    str += ( "0" );
                str += ( arr [ i ] + " " );
                i++;
            } while ( i < 100 );
        }
        /*============================================================*/
        protected override void OnPaint ( PaintEventArgs e ) {
            this.Size = new System.Drawing.Size ( 600, 300 );
            this.Text = "C# contador com loop while";
            this.BackColor = Color.Pink;
            Graphics dc = e.Graphics;
            Pen BluePen = new Pen ( Color.Red, 10 );
            dc.DrawRectangle ( BluePen, 5, 5, 575, 250 );
            Font myFont = new System.Drawing.Font ( "Consolas", 12,
                FontStyle.Italic );
            Brush myBrush = new SolidBrush ( System.Drawing.Color.Black );
            Brush myBrush_1 = new SolidBrush ( System.Drawing.Color.Red );
            dc.DrawString ( "C# contador com loop while",
                myFont, myBrush_1, 180, 15 );
            dc.DrawString ( str, myFont, myBrush, 170, 30 );
        }
        /*============================================================*/
        public Form1 ( ) {
            Ini_Array ( );
        }
    }
    /*============================================================*/
    static class Program {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main ( ) {
            Application.EnableVisualStyles ( );
            Application.SetCompatibleTextRenderingDefault ( false );
            Application.Run ( new Form1 ( ) );
        }
    }
}

Nenhum comentário:

Postar um comentário