嗨大家情況如何?VB集合轉換爲c#LinkedList
我對於我的生活一直無法弄清楚這一點。我一直在轉換GIS應用程序。我所擁有的基本上是VB中的一個集合,我需要將它轉換爲c#中的鏈表。
任何幫助入門的讚賞。
VB代碼如下
Imports ESRI.ArcGIS.esriSystem
Public Class clsFeature
Private m_OID As Integer
Private m_Geometry As ESRI.ArcGIS.Geometry.IGeometry
Public Sub New(ByRef iOID As Integer, ByRef pGeometry As ESRI.ArcGIS.Geometry.IGeometry)
m_OID = iOID
m_Geometry = pGeometry
End Sub
Public ReadOnly Property OID() As Integer
Get
OID = m_OID
End Get
End Property
Public ReadOnly Property Geometry() As ESRI.ArcGIS.Geometry.IGeometry
Get
Geometry = m_Geometry
End Get
End Property
End Class
Friend Class clsFeatureCollection
Implements System.Collections.IEnumerable
' linkedlist???????????????????????????????????????
Private m_oCol As Collection
Private m_oColReverse As Collection
Public Sub New()
MyBase.New()
m_oCol = New Collection
m_oColReverse = New Collection
End Sub
Public Sub Add(ByRef pFeature As ESRI.ArcGIS.Geodatabase.IFeature, Optional ByRef strBefore As String = "", Optional ByRef strAfter As String = "", Optional ByRef bReverse As Boolean = False)
'Create a new cFoo object based on parameters
'passed to this method, then add the new cFoo to
'the private collection, and key it by a
'unique identifier built into cFoo
'so we can retrieve it quickly later
'Add the new foo object to the collection
If bReverse Then
m_oColReverse.Add(pFeature.OID.ToString().Trim(), pFeature.OID.ToString().Trim())
End If
If Not ContainsItem(pFeature.OID.ToString().Trim()) Then
If strBefore <> "" Then
m_oCol.Add(New clsFeature(pFeature.OID, pFeature.ShapeCopy), pFeature.OID.ToString().Trim(), strBefore)
ElseIf strAfter <> "" Then
m_oCol.Add(New clsFeature(pFeature.OID, pFeature.ShapeCopy), pFeature.OID.ToString().Trim())
Else
m_oCol.Add(New clsFeature(pFeature.OID, pFeature.ShapeCopy), pFeature.OID.ToString().Trim())
End If
End If
End Sub
Public Sub AddBefore(ByRef pFeature As ESRI.ArcGIS.Geodatabase.IFeature, ByRef strBefore As String, Optional ByRef bReverse As Boolean = False)
'Create a new cFoo object based on parameters
'passed to this method, then add the new cFoo to
'the private collection, and key it by a
'unique identifier built into cFoo
'so we can retrieve it quickly later
'Add the new foo object to the collection
If bReverse Then
m_oColReverse.Add(pFeature.OID.ToString().Trim(), pFeature.OID.ToString().Trim())
End If
If Not ContainsItem(pFeature.OID.ToString().Trim()) Then
If strBefore <> "" Then
m_oCol.Add(New clsFeature(pFeature.OID, pFeature.ShapeCopy), pFeature.OID.ToString().Trim(), strBefore)
Else
m_oCol.Add(New clsFeature(pFeature.OID, pFeature.ShapeCopy), pFeature.OID.ToString().Trim())
End If
End If
End Sub
Public Sub AddAfter(ByRef pFeature As ESRI.ArcGIS.Geodatabase.IFeature, ByRef strAfter As String, Optional ByRef bReverse As Boolean = False)
'Create a new cFoo object based on parameters
'passed to this method, then add the new cFoo to
'the private collection, and key it by a
'unique identifier built into cFoo
'so we can retrieve it quickly later
'Add the new foo object to the collection
If bReverse Then
m_oColReverse.Add(pFeature.OID.ToString().Trim(), pFeature.OID.ToString().Trim())
End If
If Not ContainsItem(pFeature.OID.ToString().Trim()) Then
If strAfter <> "" Then
m_oCol.Add(New clsFeature(pFeature.OID, pFeature.ShapeCopy), pFeature.OID.ToString().Trim(), , strAfter)
Else
m_oCol.Add(New clsFeature(pFeature.OID, pFeature.ShapeCopy), pFeature.OID.ToString().Trim())
End If
End If
End Sub
Public ReadOnly Property Count() As Short
Get
'Return the number of objects in m_oCol
Count = m_oCol.Count()
End Get
End Property
Public Function GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
GetEnumerator = m_oCol.GetEnumerator
End Function
Public Sub Remove(ByRef vIndex As Object)
'Remove the specified object. Note here
'that this method will operate on either
'the index of the object we want removed
'or the key of the object we want removed
m_oCol.Remove(vIndex)
End Sub
Public Function Item(ByRef vIndex As Object) As clsFeature
'Retrieve the specified object. Note here
'that this method will operate on either
'the index of the object we want
'or the key of the object we want
Item = m_oCol.Item(vIndex)
End Function
Public Sub Clear()
'remove all objects from the private collection
m_oCol = New Collection
m_oColReverse = New Collection
End Sub
Public Function Reverse(ByRef val_Renamed As Object) As Boolean
Try
If m_oColReverse.Contains(val_Renamed) Then
Return True
Else
Return False
End If
Catch ex As Exception
If TypeOf ex Is ArgumentException Or TypeOf ex Is IndexOutOfRangeException Then
Reverse = False
End If
End Try
End Function
Public Function ContainsItem(ByRef val_Renamed As Object) As Boolean
Try
If m_oCol.Contains(val_Renamed) Then
Return True
Else
Return False
End If
Catch ex As Exception
If TypeOf ex Is ArgumentException Or TypeOf ex Is IndexOutOfRangeException Then
ContainsItem = False
End If
End Try
End Function
C#代碼 - 一旦我得到的鏈表正確的,我應該能夠完成剩下的
namespace NSTDB_QC_Utility
{
public class clsFeature
{
private int m_OID;
private IGeometry m_Geometry;
public clsFeature(int iOID, IGeometry pGeometry)
{
m_OID = iOID;
m_Geometry = pGeometry;
}
public int OID
{
get { return m_OID; }
}
public IGeometry Geometry
{
get { return m_Geometry; }
}
}
public class clsFeatureCollection : System.Collections.IEnumerable
{
// used dictionary -> Should really use a linked list because of the strBefore and strAfter
// possible but need a way to handle m_ocol and strbefore - result was to reverse m_ocol on the strBefore
public LinkedList<clsFeature> m_oCol;
// public Dictionary<int, object> m_oCol;
public Dictionary<string, string> m_oColReverse;
public clsFeatureCollection()
: base()
{
m_oCol = new LinkedList<clsFeature>();
// m_oCol = new Dictionary<int, object>();
m_oColReverse = new Dictionary<string, string>();
}
public IEnumerator GetEnumerator()
{
return m_oCol.GetEnumerator();
}
堆棧溢出不是代碼轉換服務。你試過什麼了? –
我明白這一點。我已經閱讀了很多例子..我想我無法獲得鏈接列表..以包含一個OID和幾何形狀文件。 OID將是一個Int並且幾何體將是一個對象 – Deke
'LinkedList'不是特定於C#的,它是一個NET集合;或者你的意思是你試圖將VB代碼轉換爲C#(這不是所顯示的代碼似乎在做什麼) – Plutonix