using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Collections.Generic;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //(1)
        //Button[] b;
        //(2)
        //Button[] b = new Button[3];
        //(3)
        Button[] b = new Button[3] { new Button(), new Button(), new Button() };
        Label1.Text = "" + b[0].Text;
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Label2.Text = "<BR>";
        Button[] b = new Button[3];
        for (int i = 0; i < b.Length; i++)
        {
            b[i] = new Button();
            b[i].Text = "" + i + "<BR>";
            Label2.Text += b[i].Text;
        }

        Label2.Text += "<BR>";
        foreach (Button bi in b)
        {
            bi.Text = "" + 0;
            Label2.Text += bi.Text;
        }
    }

    protected void Button3_Click(object sender, EventArgs e)
    {
        int[] losy = new int[100];
        Random r = new Random();
        for (int indeks = 0; indeks < losy.Length; indeks++)
            losy[indeks] = r.Next(100);

        Array.Sort(losy);

        ListBox1.Items.Clear();
        foreach (int los in losy) ListBox1.Items.Add("" + los);
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        int rozmiar = 100;
        Random r = new Random();
        List<int> a = new List<int>(new int[rozmiar]);
        for (int i = 0; i < rozmiar; i++) a[i] = r.Next(100);
        a.AddRange(new int[10]);
        int[] i5 ={ -1, -1, -1, -1, -1 };
        a.InsertRange(rozmiar / 2, i5);
        a.Insert(0, 1);

        /*
        for (int i = 0; i < a.Count; i++)
        {
            if ((int)a[i] > 20)
            {
                a.RemoveAt(i);
                i--;
            }
        }
        */

        int j = 0;
        do
        {
            if ((int)a[j] > 20)
                a.RemoveAt(j);
            else
                j++;
        }
        while (j < a.Count);

        a.Sort();
        ListBox1.Items.Clear();
        foreach (object ai in a) ListBox1.Items.Add("" + ai);
    }
    protected void Button5_Click(object sender, EventArgs e)
    {
        SortedList<string, string> artysci = new SortedList<string, string>();
        artysci.Add("Sting", "Gordon Matthew Sumner");
        artysci.Add("Bolesław Prus", "Aleksander Głowacki");
        artysci.Add("Pola Negri", "Barbara Apolonia Chałupiec");
        artysci.Add("John Wayne", "Marion Michael Morrison");
        artysci.Add("Chico", "Leonard Marx");
        artysci.Add("Harpo", "Arthur Marx");
        artysci.Add("Groucho", "Julius Marx");
        artysci.Add("Bono", "Paul Hewson");
        artysci.Add("Ronaldo", "Luiz Nazario de Lima");
        artysci.Add("Madonna", "Madonna Louise Veronica Ciccone");
        artysci.Add("Gabriela Zapolska", "Maria G. Śnieżko-Błocka");

        string komunikat = "<BR><B>Zawartość listy:</B><BR>:";
        foreach (KeyValuePair<string, string> artysta in artysci)
            komunikat += artysta.Key + " - " + artysta.Value + "<BR>";
        Label5.Text=komunikat;
    }
}
