0
參考問題Creating a custom ordered dictionaryOrderedDictionary返回一個Item?
我正在使用OrderedDictionary,因爲我需要跟蹤鍵和輸入值的順序。
我想獲得該項目,並將其返回到該行:
pPolyline = (IPolyline)colConnectedFeatures.Item(i).Geometry;
我正在尋找一種方式來回報的項目?我使用GetObjectData嗎?我需要序列化嗎?
private static IPolyline BuildPolyline(clsFeatureCollection colConnectedFeatures, Hashtable htChecked)
{
for (int i = 0; i < colConnectedFeatures.Count; i++)
{
pPolyline = (IPolyline)colConnectedFeatures.Item(i).Geometry;
if (colConnectedFeatures.Reverse(colConnectedFeatures.Item(i).OID.ToString().Trim()))
{
pPolyline.ReverseOrientation();
}
}
public class clsFeature
{
private int m_OID { get; set; }
private IGeometry m_Geometry { get; set; }
public clsFeature(int iOID, IGeometry pGeometry)
{
this.m_OID = iOID;
this.m_Geometry = pGeometry;
}
public int OID
{
get { return m_OID.GetHashCode(); }
}
public IGeometry Geometry
{
get { return m_Geometry; }
}
public override int GetHashCode()
{
return OID.GetHashCode();
}
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
return base.Equals(obj);
}
}
public class clsFeatureCollection : IEnumerable
{
// ************************** Ordered Dictionary ****************
// https://stackoverflow.com/questions/2722767/c-sharp-order-preserving-data-structures
// http://www.go4expert.com/articles/understanding-c-sharp-dictionaries-t30034/
public OrderedDictionary m_oCol;
public clsFeatureCollection()
: base()
{
m_oCol = new OrderedDictionary();
}
public clsFeature Item(int Position)
{
// object key = m_oCol.Cast<DictionaryEntry>().ElementAt(Position).Key;
// object value = m_oCol.Cast<DictionaryEntry>().ElementAt(Position).Value;
clsFeature clsValue = default(clsFeature);
object[] keys = new object[m_oCol.Keys.Count];
object[] values = new object[m_oCol.Values.Count];
m_oCol.Keys.CopyTo(keys, 0);
m_oCol.Values.CopyTo(values, 0);
for (int i = 0; i < m_oCol.Keys.Count; i++)
{
Console.WriteLine("Index = {0}, Key = {1}, Value = {2}", i, keys[i], m_oCol[i]);
}
return (clsFeature)clsValue;
}
您有什麼特別的問題?你是否要求[代碼評論](http://codereview.stackexchange.com/)? – 31eee384
我很想念一些泛型。 'OrderedDictionary'首次在.NET 2.0中引入,泛型也是如此。還有'IEnumerable'和'HashTable'。 – Caramiriel
@Deke也許您可以詢問您的解決方案中的具體問題。如果我們不知道你想解決什麼問題,這只是一個代碼審查。 (編輯迴應編輯:我應該更明確地說:Stack Overflow不是代碼評論的地方,請查看我評論中對於這個地方的鏈接。) – 31eee384