高手赶紧过来啊 急用!!!!!!!

解决方案 »

  1.   

    只要是一行四个词以;分隔就可以
    这就是规律啊
      

  2.   

    定义test.txt
    Google;45;false;CC33FF
    Baidu;35;false;6666FF
    Yahoo;20;false;FFCC00using System;
    using System.Data;
    using System.IO;
    using System.Text;public class MyClass
    {
        /// <summary>
        /// 定义继承自table
        /// </summary>
        class MyTable : DataTable {
            private string fileName = "..\\..\\test.txt";
            public MyTable() {
                Columns.Add("name",typeof(string));
                Columns.Add("int", typeof(int));
                Columns.Add("bool", typeof(bool));
                Columns.Add("color", typeof(string));
            }
            /// <summary>
            /// 保存为文本文件
            /// </summary>
            public void Save(){
                using (StreamWriter sw = new StreamWriter(fileName,false, Encoding.ASCII))
                {
                    foreach (DataRow dr in Rows)
                    {
                        sw.WriteLine("{0};{1};{2};{3}", new object[] { dr[0],dr[1],dr[2],dr[3] });
                    }
                }
            }
            /// <summary>
            /// 从文本文件读取初始信息,也可以在初始化时完成,不用load
            /// </summary>
            public void Load() {
                
                using (StreamReader sr = new StreamReader(fileName, Encoding.ASCII)) {
                    string line;
                    while (( line = sr.ReadLine()) != null)
                    {
                        string[] data = line.Split(new char[] { ';' });
                        Rows.Add(new object[] { data[0], data[1], data[2], data[3] });
                    }
                    sr.Close();
                }            
            }
            
        }
        public static void Main()
        {
            try
            {
                //然后可以象操作datatable一样实现数据功能            MyTable tab = new MyTable();
                tab.Load();
                tab.Rows[0][0] = "hello";
                tab.Rows.RemoveAt(2);
                tab.Save();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            finally
            {
                Console.WriteLine("END");
                Console.Read();
            }
        }
    }