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 1113555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:52:35+00:00 2026-05-17T02:52:35+00:00

Apologies for the appalling title. I have mocked up this code to mimic an

  • 0

Apologies for the appalling title.

I have mocked up this code to mimic an issue I was encountering on a project.

I want to know why the property status does not ‘stick’. Stepping through the code I can even see it setting the property!

Is it something to do with Structure being a value type?

Here is the code, it is standalone.

Imports System.Diagnostics

Public Class clsTest
    Public Shared Sub test()
        Dim myHolder As New holder

        myHolder.info = New info(5)
        With myHolder.info
            Debug.Print("Initialised Status : {0}", .status)
            Debug.Print("Initialised Original Status : {0}", .originalStatus)
            myHolder.setStatusToTen()
            Debug.Print("Next Status : {0}", .status)
            Debug.Print("Next Original Status : {0}", .originalStatus)
        End With
    End Sub
End Class

Public Class holder
    Private _heldInfo As info

    Public Property info() As info
        Get
            Return _heldInfo
        End Get
        Set(ByVal value As info)
            _heldInfo = value
        End Set
    End Property

    Public Sub setStatusToTen()
        _heldInfo.status = 10
    End Sub
End Class

Public Structure info
    Private _iOriginalStatus, _iStatus As Integer

    Public Sub New(ByVal iStartingStatus As Integer)
        _iOriginalStatus = iStartingStatus
    End Sub

    Public ReadOnly Property originalStatus() As Integer
        Get
            Return _iOriginalStatus
        End Get
    End Property

    Public Property status() As Integer
        Get
            Return _iStatus
        End Get
        Set(ByVal value As Integer)
            _iStatus = value
        End Set
    End Property
End Structure

When I run clsTest.test I get the following output-

clsTest.test
Initialised Status : 0
Initialised Original Status : 5
Next Status : 0
Next Original Status : 5

…even though setStatusToTen is doing exactly what it says on the tin!

  • 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-17T02:52:36+00:00Added an answer on May 17, 2026 at 2:52 am

    Yes, its because Structures are value types. When a struct object is assigned to another struct object, the full content of the struct is copied and duplicated. (See this C# example)

    So in your code, this set:

    Set(ByVal value As info)
            _heldInfo = value
    End Set
    

    … effectively results in two copies of the structure being made. One is internal to holder and is represented by _heldInfo, and the other is ‘external’ to holder, and is represented by myHolder.info. After the copy has been made, when you set values on one of them, the other is not affected.

    If you add this method to holder:

    Public Sub printStatus()
        Debug.Print("Internal Status : {0}", _heldInfo.status)
    End Sub
    

    … you will find where your value of 10 went.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.