日期:2014-05-18 浏览次数:21005 次
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……不好好上学跑出来的罪过啊。
------解决方案--------------------
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();