首先,您需要花一些时间熟悉该语言的基础知识才能提高工作效率。我建议你花一点时间在C#上阅读太深的内容 - 否则你会花很多时间旋转你的轮子 - 或重塑他们:)
但是,这里有一些信息让你开始。
通常,在C#中,您可以创建类来表示程序的元素 - 包括用于表示程序想要操作的信息(数据)的类。你应该考虑使用它,因为它会使数据操作更清晰,更易于管理。我建议避免像某些人所暗示的无类型的多维数组结构,因为这些结构很快就变得非常难以使用。
可以使用自动属性和一个简单的构造容易地创建在C#中介绍朋友类:
public class Referall
{
// these should be named in line with what they represent...
public string FirstString { get; set; }
public string AnotherString { get; set; }
public int SomeValue { get; set; }
public Referall(string first, string another, int value)
{
FirstString = first;
AnotherString = another;
SomeValue = value;
}
}
您可以添加这些以字典为您创建它们 - 字典可以键入由曾经属性独特。词典让你基于一个独特的密钥存储对象:如果你需要你的时候到项目的字典排序
Referall ref = new Referall(v1, v2, v3);
// add to the dictionary, keying on FirstString...
dict.Add(ref.FirstString, ref);
:
Dictionary<string,Referall> dict = new Dictionary<string,Referall>();
如您处理的项目,你可以将它们添加到字典大功告成了,你可以在C#3.0中使用LINQ:
IEnumerable<Referall> sortedResults =
dict.Values.OrderBy(x => x.AnotherString);
您可以通过使用ThenBy(多维排序),以及:
IEnumerable<Referall> sortedResults =
dict.Values.OrderBy(x => x.AnotherString)
.ThenBy(x => x.SomeValue);
嗯,你是什么意思的'独特ify'?你想提取一个独特的推荐对象列表? – 2009-07-21 18:12:53
听起来像你应该有一个快速阅读这个http://msdn.microsoft.com/en-gb/library/ybcx56wz.aspx – 2009-07-21 21:44:48