在3.0以上,可以给list<float>加个扩展方法来统计,当然,你也可以放外头统计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 ListExMethodNS { public static class ListExMethod { static int TotalCount = 0; public static int AddEx(this List<double> L, double F) { L.Add(F); return ++TotalCount; } } }namespace WindowsFormsApplication24 { using ListExMethodNS; public partial class Form1 : Form { public Form1() { InitializeComponent(); List<double> L = new List<double>(10); MessageBox.Show(L.AddEx(5).ToString()); MessageBox.Show(L.AddEx(8).ToString()); MessageBox.Show(L.AddEx(10.5).ToString()); } } }
{
List<float> a1 = new List<float>();
a1.Add(5.0F);
a1.Add(0);
a1.Add(0);
a1.Add(0); for (int i = 0; i < a1.Count; i++)
{
MessageBox.Show(a1[i].ToString());
}
}
int listCount = 0; //当前值
private bool IsAdded()
{
if (a1.Count > listCount)
{
listCount = a1.Count;
return true;
}
else return false;
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace ListExMethodNS
{
public static class ListExMethod
{
static int TotalCount = 0; public static int AddEx(this List<double> L, double F)
{
L.Add(F);
return ++TotalCount;
}
}
}namespace WindowsFormsApplication24
{
using ListExMethodNS; public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
List<double> L = new List<double>(10); MessageBox.Show(L.AddEx(5).ToString());
MessageBox.Show(L.AddEx(8).ToString());
MessageBox.Show(L.AddEx(10.5).ToString());
}
}
}
int a,b;
a=b;
确保出错