Array of structure

Discussion in 'ASP .Net' started by Leon, Jan 14, 2010.

  1. Leon

    Leon Guest

    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
     
    Leon, Jan 14, 2010
    #1
    1. Advertising

  2. Leon

    Leon Guest

    Thank you Mark.
    I'll try that.

    "Mark Rae [MVP]" wrote:

    > "Leon" <> wrote in message
    > news:...
    >
    > > but hope there is a better way to do this.

    >
    > 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
    >
    > > Then you would simply call the .ContainsKey(...) method to determine
    > > whether that key already exists:

    > 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
    >
    > .
    >
     
    Leon, Jan 16, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Excluded_Middle

    Pointers to structure and array of structure.

    Excluded_Middle, Oct 24, 2004, in forum: C Programming
    Replies:
    4
    Views:
    757
    Martin Ambuhl
    Oct 26, 2004
  2. Leo Nunez
    Replies:
    3
    Views:
    1,230
    Neil Kurzman
    Feb 9, 2005
  3. Replies:
    2
    Views:
    610
  4. Replies:
    9
    Views:
    25,316
    Lal Bahadur Singh
    Nov 11, 2011
  5. meisterbartsch
    Replies:
    2
    Views:
    787
    meisterbartsch
    Jun 12, 2007
Loading...

Share This Page