C#结构体排序
1.................................................
声明
struct data
{
public string A;
public string B;
}
创建测试数据
data[] st = new data[4]
{
new data() { A = "CC", B = "003" },
new data() { A = "BB", B = "002" },
new data() { A = "DD", B = "005" },
new data() { A = "AA", B = "007" }
};
按照 data.B 顺序排列
data[] basc = st.OrderBy(P => P.B).ToArray<data>();
按照 data.B 倒序排列
data[] bdesc= st.OrderByDescending(P => P.B).ToArray<data>();
2..........................................................
struct data:IComparable<data>
{ string A;
string B;
public int CompareTo(data d){
return this.B.CompareTo(d.B);
}
}
队列
DirectoryInfo tou = null, xin = null;//文件类型
xin = (DirectoryInfo)s;//把参数s强制转换
Queue<DirectoryInfo> q = new Queue<DirectoryInfo>();
q.Enqueue(xin);//进队列
while (q.Count() != 0)//判断是否为空
tou = q.First();//取出
q.Dequeue();//删除
容器
static Dictionary<string, int> mark = new Dictionary<string, int>();
mark[myProcess.ProcessName] = 1; 赋值
mark.Remove();删除
mark.ContainsKey()查是否存在