首先,您需要花一些時間熟悉該語言的基礎知識才能提高工作效率。我建議你花一點時間在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