Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 521499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:15:24+00:00 2026-05-13T08:15:24+00:00

I have a property which is an array of items, but when I come

  • 0

I have a property which is an array of items, but when I come to add an item to the array it says I must use the new keyword, but I can’t use a new keyword with a property.

(item is a custom class.)

Private itemsvalue As item()
Public Property Items() As item()
    Get
        Return itemsvalue
    End Get
    Set(ByVal value As DBPFindexitem())
        itemsvalue = value
    End Set
End Property

Sub New(ByVal indexbytes As Byte(), ByVal number as integer)

     For count As Integer = 0 To number
        Dim offset As Integer = count * 2 * 4
        Dim xx As New item
        xx.Group = BitConverter.ToInt32(indexbytes, offset + 0)
        xx.ID = BitConverter.ToInt32(indexbytes, offset + 8)
        Items(count) = xx
    Next
End Sub

How can I add the xx item to the array of items?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T08:15:24+00:00Added an answer on May 13, 2026 at 8:15 am

    You should be using a collection instead of an array.
    A Collection will automatically resize to hold as many items as you put into it.

    For example:

    Private itemsvalue As New List(Of item)
    Public Property Items() As List(Of item)
        Get
            Return itemsvalue
        End Get
        Set(ByVal value As List(Of item))
            itemsvalue = value
        End Set
    End Property
    
    Sub New(ByVal indexbytes As Byte(), ByVal number as integer)
         For count As Integer = 0 To number
            Dim offset As Integer = count * 2 * 4
            Dim xx As New item
            xx.Group = BitConverter.ToInt32(indexbytes, offset + 0)
            xx.ID = BitConverter.ToInt32(indexbytes, offset + 8)
            Items.Add(xx)    
        Next
    End Sub
    

    If you’re writing a public library, you should use a System.Collections.ObjectModel.Collection(Of item) instead. This will allow you to replace it later with an inherited collection with special behavior, without breaking existing clients. See here.

    If you don’t want other people to modify the collection, you should expose a
    System.Collections.ObjectModel.ReadOnlyCollection(Of item).


    If you really want to use an array, you should initialize the array, like this:

    Items = New item(number)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a NSTreeController which array is bound to a items (custom) property of
I have a property column which can have a subset of the following values
In msbuild/xbuild I'd like to have a libPath property which can be ovveridden on
I'm building an array of objects which have a property of type array: here's
I have a few classes which have a property which is unique to that
In C# 3.0, I have a property which is suppose to contain the version
I have two collections which have property Email in both collections. I need to
I have requirement like, suppose I have a 'property' table which has 'ListingKey' field
I'm using the Validation Application Block from Microsoft. I have a string property which
I have written a attached property which stores amongst others a help text. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.