首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

小弟求代码,高分送下,拜托各位大神啦!

2012-09-02 
小弟求代码,高分送上,拜托各位大神啦!!!我想只写一个方法给listbox赋值,并写入txt文件:listbox中每写一次

小弟求代码,高分送上,拜托各位大神啦!!!
我想只写一个方法给listbox赋值,并写入txt文件:

  listbox中每写一次数据,就同时写入txt文件,listbox中的数据最多显示20条(按时间),后面每进一条数据,就把最前面的一条数据清除,总数一定是20条。写入文本txt文件时,数据按时间不能重复,每当数据超过一万条时,重建新的文本以时间为名称,再输入数据。。。


拜托各位大神啦!!!
 

[解决办法]
添加时判断

C# code
            if (listBox1.Items.Count == 20)                listBox1.Items.RemoveAt(0);            listBox1.Items.Add("a");
[解决办法]
http://msdn.microsoft.com/zh-cn/library/7977ey2c.aspx

看看这个Queue<T>类及下面的示例
[解决办法]
队列不明白么?first in first out……不好好上学跑出来的罪过啊。
[解决办法]
C# code
string yourfilepath="你要存储的文件路径";            StreamReader reader = new StreamReader(yourfilepath);            StreamWriter writer;            int count = 0;         //   string[] aa=new string[]{System.Environment.NewLine};            count = reader.ReadToEnd().Split(new string[] { System.Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).Length;            //或 while(reader .ReadLine())count++;            reader.Close();            if (count > 10000)            {                int index = yourfilepath.LastIndexOf("+");                int n ;                int.TryParse(index == -1 ? "0" : (yourfilepath.Substring(index == -1 ? 0 : index + 1)),out n);//序号                int indextemp = yourfilepath.Substring(0, index == -1 ? 0 : index).LastIndexOf("+");                string temp = yourfilepath.Substring(0, indextemp == -1 ? (yourfilepath.Length - 1) : indextemp);                string newfilepath = (n == 0 ? string.Empty : temp) + DateTime.Today.ToLongDateString() + "+" + (n + 1).ToString();                writer = new StreamWriter(newfilepath);            }            else writer = new StreamWriter(yourfilepath);            writer.WriteLine("你要存储的信息");            writer.Flush();             writer.Close(); 

热点排行