Public Structure inventoryPartInfo
Dim partNumber As String
Dim partDescription As String
End Structure
Dim microController As New List(Of inventoryPartInfo)
Dim newControl As New inventoryPartInfo
newControl.PartNumber = "11435-AC-AB-X"
newControl.PartDescription = "Cirrus Dual-Band Gate"
microController.Add (newControl)
newControl = Nothing
11435-AC-AB-X Cirrus Dual-Band Gate
23907-FX-BA-W Rabbit Data Manifold
21340-TF-AB-A Drax Ring Buffer
54384-FX-BA-A Prillex Transfer Enhancer
11435-AC-AB-X Cirrus Dual-Band Gate
21340-TF-AB-A Drax Ring Buffer
54384-FX-BA-A Prillex Transfer Enhancer
23907-FX-BA-W Rabbit Data Manifold
Public Class CompInventoryPartNumber
Implements IComparer(Of inventoryPartInfo)
Public Function Compare(x As inventoryPartInfo, y As inventoryPartInfo) As Integer Implements System.Collections.Generic.IComparer(Of inventoryPartInfo).Compare
Return String.Compare(x.partNumber, y.partNumber)
End Function
End Class
Rather than just using a plain structure, use a class. Then you can override methods such asIs there something I don't know about which prevents one from overriding methods in a struct?
Public Structure inventoryPartInfo
Dim partNumber As String
Dim partDescription As String
Public Overrides Function ToString() As String
Return "Hello World!"
End Function
End Structure
Public Class CompInventoryPartDescription
Implements IComparer(Of inventoryPartInfo)
Public Function Compare(x As inventoryPartInfo, y As inventoryPartInfo) As Integer Implements System.Collections.Generic.IComparer(Of inventoryPartInfo).Compare
Return String.Compare(x.partDescription, y.partDescription)
End Function
End Class
ASKER
but this was the solution that resolved the problem with the least amount of code invasion, which results in fewer bugs later on.But you've actually modified the behavior of the structure itself. I'd say that has the potential for a bug. With PaulHew's approach, you are adding a new entity which contains the functionality you desire, but does not modify the original structure definition--it's completely separate. And as he already mentioned, that approach is much more extensible/expandable than implementing IComparable would be.
Visual Basic .NET (VB.NET) is an object-oriented programming language implemented on the .NET framework, but also supported on other platforms such as Mono and Silverlight. Microsoft launched VB.NET as the successor to the Visual Basic language. Though it is similar in syntax to Visual Basic pre-2002, it is not the same technology,
TRUSTED BY
See a very good clear example here....
http://www.vbforums.com/showthread.php?t=310363