using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebArray
{
    public partial class Default : System.Web.UI.Page
    {
        // Create an array.
        String[] TestArray;

        protected void Page_Load(object sender, EventArgs e)
        {
            // Initialize the array.
            TestArray = new String[] { "One", "Two", "Three", "Four", "Five" };
        }

        protected void btnLINQ_Click(object sender, EventArgs e)
        {
            // Create the query.
            var Output = from String TheEntry
                         in TestArray
                         select TheEntry.Substring(0, 3);

            // Display one of the results.
            txtOutput.Text = Output.ToArray<String>()[2];

            //// Display an alert instead.
            //HttpContext.Current.Response.Write(
            //    "<SCRIPT LANGUAGE='JavaScript'>alert('" +
            //    Output.ToArray<String>()[2] +
            //    "')</SCRIPT>");
        }

        protected void btnLoop_Click(object sender, EventArgs e)
        {
            // Create a variable to hold the result.
            String Output = "";

            // Perform the array processing.
            for (Int32 Counter = 0; Counter < TestArray.Length; Counter++)
            {
                Output = Output + TestArray[Counter] + "\r\n";
            }

            // Display the result on screen.
            txtOutput.Text = Output;
        }

        protected void btnConditional_Click(object sender, EventArgs e)
        {
            // Create a variable to hold the result.
            String Output = "";

            // Perform the array processing.
            for (Int32 Counter = 0; Counter < TestArray.Length; Counter++)
            {
                // Place a condition on the task. Perform the task only for the
                // third array element.
                if (Counter == 2)
                {
                    Output = Output + TestArray[Counter].Substring(0, 3) + "\r\n";
                }
            }

            // Display the result on screen.
            txtOutput.Text = Output;
        }
    }
}