ZengCode.Com (The Thai Php Framework)  


Home   Download   Manual   About us    

Facebook   


MAIN MENU
เขียนโปรแกรมบน iPhone ด้วย MonoTouch
News
Php Tips
Ubuntu
Spring+Strut+Hibernate
Android Programming
Design Pattern By PHP
C# Design Pattern
Linux Quick Tips
C# Tips & Technique
C# using Linq น่าใช้จริงๆ
Java & JavaScript Tips
MAVEN
Database & SQL
ZengCode Framework Guide
Mac OSx
Zeng Code Code
Programming
IPhone (Tips and Trick)

Download เอกสารที่น่าสนใจ

     การ grouping, sum, average   (2009-12-28)

  public class InputData
    {
        public String grouping;
        public double salary;
    }

    public class ImportExport
    {
        public ArrayList ImportData(String sourceFile)
        {
            ArrayList al = new ArrayList();
            StreamReader re = File.OpenText(sourceFile);
            string input = null;
            while ((input = re.ReadLine()) != null)
            {
                string[] words = input.Split(',');
                InputData ipData = new InputData();
                ipData.grouping = words[0];
                ipData.salary = Convert.ToDouble(words[1]);
                al.Add(ipData);
            }
            re.Close();
            return al;

        }

    }

 

 

var ResultData =
                             from InputData data in inputDataArrayList
                             group data by data.grouping into newData
                             select new
                             {
                                 Grouping = newData.Key,
                                 SumSalary = newData.Sum(data => data.salary),
                                 AverageSalary = newData.Average(data => data.salary),
                                 CountAll = newData.Count()
                             };

            //foreach (var data in categoryCounts)
             //   MessageBox.Show("> group " + data.Grouping + " > sum > " + data.SumSalary + " > average >" + data.AverageSalary + " > countAll >" + data.CountAll);

            var fileName = txtDest.Text;
           // fileName = "c:\\test.html";

            using (StreamWriter sw = new StreamWriter(fileName))
            {
                sw.WriteLine("header for the file.");
                sw.WriteLine("-------------------");
                // Arbitrary objects can also be written to the file.
                sw.Write("The date is: ");
                sw.WriteLine(DateTime.Now);
                sw.WriteLine("Grouping,Sum Salary,Average Salary,Count of Members");
                foreach (var data in ResultData)
                    sw.WriteLine(data.Grouping + "," + data.SumSalary + "," + data.AverageSalary + "," + data.CountAll);
                sw.Close();
            }


Comment

ZengCode  (04 มกราคม 2553)   
IP : 203.154.112.163

ไม่รู้เขียนยืดยาวไปป่าวครับ มีใครเซียนๆ บ้าง นี่ผมเพิ่งหัดเขียนอันแรกครับ


Name
Comment
Security CodeCAPTCHA Image

web hit counter

This page took 0.042756 seconds to load.