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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:56:00+00:00 2026-05-18T03:56:00+00:00

VB.NET 2010, .NET 4 Hello all, I’m by no means a good programmer and

  • 0

VB.NET 2010, .NET 4

Hello all,

I’m by no means a good programmer and I’m just trying to wrap my head around some of this stuff, so please forgive me if this is a dumb question.

I want the following to produce a message box that says “2”, not “5”:

Public Class SomeClass
  Private SomeInt As Integer = 5
  Private SomeListOfInts As New List(Of Integer)

  Public Sub New()
    SomeListOfInts.Add(SomeInt)
    SomeListOfInts(0) = 2
    MsgBox(SomeInt.ToString)
  End Sub
End Class

This doesn’t work. The message box says “5”. I think that I understand why to some degree. Since SomeInt is a value type, adding it to SomeListOfInts just adds a copy. I’m sorry if this is incoherent. Is there any straightforward way to accomplish this?

Thanks in advance,
Brian

Edit: I just wanted to add, I suspect folks’ll say “Why try to do this?”/”This is not a good thing to try to do.” etc. I’m alright with that and would like to know a better approach if there is one, however, I am also generically curious about how something like this might be done, whether it’s good practice or not. Also, if it isn’t good practice (whatever that means), why?

  • 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-18T03:56:01+00:00Added an answer on May 18, 2026 at 3:56 am

    It is output 5 because your MsgBox is referencing SomeInt, not SomeListOfInts(0)

    Try this:

    Public Class SomeClass
      Private SomeInt As Integer = 5
      Private SomeListOfInts As New List(Of Integer)
    
      Public Sub New()
        SomeListOfInts.Add(SomeInt)
        SomeListOfInts(0) = 2
        MsgBox(SomeListOfInts(0).ToString) // here is the change
      End Sub
    End Class
    

    This…

    SomeListOfInts(0) = 2
    

    changes indexed element 0 in your list from 5 (the original value of element 0) to 2. Also, int is a value type. Therefore, when you add SomeInt to the list, you have created a copy of the value type. The copy can be changed without affecting the original SomeInt.

    You could start with:

    Private ListOfInts As New List(Of Integer)

    Public Sub New(SomeInt As Integer)
        ListOfInts.Add(SomeInt)
    
        ' processes
    
        ListOfInts(0) = 2
        MsgBox(SomeListOfInts(0).ToString)
    End Sub
    

    Maybe with a little more background on exactly what you are trying to do, I can help you get closer to your expectations.

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

Sidebar

Related Questions

.NET balanced group regexes make my head explode. I've got this string i'm trying
I installed VS.Net 2010 to play around with some of the new C# features
Question: Assume a C++ hello world program, non .NET. With Visual Studio 2005/2008/2010, how
VS.net 2010/.net 4.0 RC was just released. For those who have used Beta or
I am trying to make my first program in vb.net 2010, and I have
I just finished building my program, but I noticed that vb.net (2010) creates two
Is Linq included in .net 2010 i.e. .NET 4.0
With the recent announcement of .NET 4.0 and Visual Studio 2010, it is becoming
.NET has a lot of complex data structures. Unfortunately, some of them are quite
.Net's implementation of HTTP is ... problematic. Beyond some issues in compliance with HTTP/1.0,

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.