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

  • SEARCH
  • Home
  • 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 8377279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:37:52+00:00 2026-06-09T15:37:52+00:00

I have custom class like the below; Public MyClass Public Property MyText() As String

  • 0

I have custom class like the below;

Public MyClass
  Public Property MyText() As String
End Class

Then in my code page I have the following VB.NET code;

Dim obj1 As New MyClass
Dim obj2 As New MyClass

obj1 = obj2
obj1.MyText = "Test"

My problem is that when the below piece of code is executed the obj2.MyText is updated as well. How can I avoid this?

obj1.MyText = "Test"

Thanks.

  • 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-06-09T15:37:54+00:00Added an answer on June 9, 2026 at 3:37 pm

    This is the problem:

    obj1 = obj2
    

    That copies the value of obj2 to obj1. That value is not the object – it’s a reference to the object. So now obj1 and obj2 refer to the same object, so any changes you make via one variable will be seen by the other.

    I realize this is VB rather than C#, but you may still find my article on reference types and value types useful. Fundamentally, you need to grok how reference types behave.

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

Sidebar

Related Questions

I have a class with a custom indexer like so public string this[VehicleProperty property]
I have a custom property called Questions the code is below. public class Questions
I have written a custom server control which (pseudo-code) looks like public class MyCustomCtrl
say, I have a partial class that contains a custom property like this public
I have Custom List to display image with it's name like below... public class
I have a custom class class RouteStop { public int number; public string location;
I have a class ComponentItem which i simplified (pseudo code) below public class ComponentItem
I have made my custom In extension method as shown below: public static class
I have a custom class that uses boost mutexes and locks like this (only
I have a custom container class for which I'd like to write the iterator

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.