Just not as pretty as C# but here is my take
Also SMCD, IMO you were correct in using a Class instead of a Struct (its too big to be a struct)
Public Class Contacts
Inherits List(Of Contact)
' Methods
Public Sub New()
End Sub
Public Sub New(ByVal contacts As IEnumerable(Of Contact))
Dim con As Contact
For Each con In contacts
MyBase.Add(con)
Next
End Sub
End Class
Public Class Contact
Implements IComparable
' Methods
Public Sub New()
Me.m_Name = String.Empty
Me.m_Prop1 = String.Empty
Me.m_Prop2 = String.Empty
Me.m_Prop3 = String.Empty
Me.m_Prop4 = String.Empty
End Sub
Public Sub New(ByVal stringArray As String())
Me.FromArray(stringArray)
End Sub
Public Sub New(ByVal name As String, ByVal prop1 As String, ByVal prop2 As String, ByVal prop3 As String, ByVal prop4 As String)
Me.m_Name = name
Me.m_Prop1 = prop1
Me.m_Prop2 = prop2
Me.m_Prop3 = prop3
Me.m_Prop4 = prop4
End Sub
Public Function CompareTo(ByVal obj As Object) As Integer
If Not TypeOf obj Is Contact Then
Throw New ArgumentException("Object is not a Contact.")
End If
Dim c2 As Contact = DirectCast(obj, Contact)
Return Me.m_Name.CompareTo(c2.m_Name)
End Function
Public Overrides Function Equals(ByVal obj As Object) As Boolean
If (obj Is Nothing) Then
Return False
End If
If Object.ReferenceEquals(Me, obj) Then
Return True
End If
If (Not MyBase.GetType Is obj.GetType) Then
Return False
End If
Dim objContact As Contact = DirectCast(obj, Contact)
Return Me.m_Name.ToUpper.Equals(objContact.m_Name)
End Function
Public Sub FromArray(ByVal StringArray As String())
Dim i As Integer
For i = 0 To 5 - 1
If (StringArray(i) Is Nothing) Then
StringArray(i) = String.Empty
End If
Next i
Me.m_Name = StringArray(0)
Me.m_Prop1 = StringArray(1)
Me.m_Prop2 = StringArray(2)
Me.m_Prop3 = StringArray(3)
Me.m_Prop4 = StringArray(4)
End Sub
Public Overrides Function GetHashCode() As Integer
Return Me.m_Name.GetHashCode
End Function
Public Function ToArray() As String()
Return New String() { Me.m_Name, Me.m_Prop1, Me.m_Prop2, Me.m_Prop3, Me.m_Prop4 }
End Function
Public Overrides Function ToString() As String
Dim sb As New StringBuilder
sb.Append(Me.m_Name)
sb.Append(",")
sb.Append(Me.m_Prop1)
sb.Append(",")
sb.Append(Me.m_Prop2)
sb.Append(",")
sb.Append(Me.m_Prop3)
sb.Append(",")
sb.Append(Me.m_Prop4)
Return sb.ToString
End Function
' Properties
Public Property Name As String
Get
Return Me.m_Name
End Get
Set(ByVal value As String)
Me.m_Name = value
End Set
End Property
Public Property Prop1 As String
Get
Return Me.m_Prop1
End Get
Set(ByVal value As String)
Me.m_Prop1 = value
End Set
End Property
Public Property Prop2 As String
Get
Return Me.m_Prop2
End Get
Set(ByVal value As String)
Me.m_Prop2 = value
End Set
End Property
Public Property Prop3 As String
Get
Return Me.m_Prop3
End Get
Set(ByVal value As String)
Me.m_Prop3 = value
End Set
End Property
Public Property Prop4 As String
Get
Return Me.m_Prop4
End Get
Set(ByVal value As String)
Me.m_Prop4 = value
End Set
End Property
' Fields
Protected m_Name As String
Protected m_Prop1 As String
Protected m_Prop2 As String
Protected m_Prop3 As String
Protected m_Prop4 As String
End Class