วันเสาร์ที่ 14 มกราคม พ.ศ. 2555

แบบฝึกหัดครั้งที่ 6

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
             double[] waterDepht = { 45, 19, 2, 16.8, 190, 0.8, 510, 6, 18 };
            string outputMsg = "";
            string caption = "System.Array Methods IIIustrated";
            double[] w = new double[20];
            outputMsg += "waterDepth Array\n\n";
            foreach (double wVal in waterDepht)
                outputMsg += wVal + "\n";
            MessageBox.Show(outputMsg, caption);
            Array.Copy(waterDepht, 2, w, 0, 5);
            Array.Sort(w);
            outputMsg = "Array w Sorted\n\n";
            foreach (double wVal in w)
            {
                if (wVal > 0)
                    outputMsg += wVal + "\n";
            }
            MessageBox.Show(outputMsg, caption);
            Array.Reverse(w);
            outputMsg = "Array w Reversed\n\n";
            foreach (double wVal in w)
            {
                if (wVal > 0)
                    outputMsg += wVal + "\n";
            }
            MessageBox.Show(outputMsg, caption);
        

            InitializeComponent();
        }

    }
}






ไม่มีความคิดเห็น:

แสดงความคิดเห็น