Array of structure

  • Thread starter Thread starter Leon
  • Start date Start date
L

Leon

Hi Everybody

I have a small structure
Structure SkuInfo
Dim SkuNo As String
Dim Priority As Integer
End Structure
and Array

Dim arrSkus() As SkuInfo

Before adding next element to this array I want to make sure
that I do not have elements with the same SKUNO.

I am trying to use indexof, but do not know how to use it with array of
structures.
I realize I can use For... Next loop, but hope there is a better way to do
this.

Thanks in advance
 
Thank you Mark.
I'll try that.

Mark Rae said:
Firstly, I would not use an array for this. Instead, I'd use a Dictionary
generic. Generics were introduced in .NET Framework v2, and are many times
more powerful and function-rich than arrays. A Dictionary would allow you to
add the structure *and* reference it by its SkuNo:
http://msdn.microsoft.com/en-us/library/xfhwa508.aspx

http://msdn.microsoft.com/en-us/library/kw5aaea4.aspx


Alternatively, you could use (probably) use LINQ to query the array:
http://www.google.co.uk/search?rlz=...28&aq=f&sourceid=chrome&ie=UTF-8&q=LINQ+array

However, the generic method will be much simpler, and probably much
faster...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

.
 
Back
Top