Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15743

VS 2012 List of Data

$
0
0
Hello,

What I am doing is creating 2 lists. Adding the same variable to each, altering the value in the first list, and seeing if the value changes in the second list.

Button 1 uses a simple string, and the message box result is 123
Button 2 uses a custom class, and the message box result is 666

I don't really know what to search for so can anyone explain what is happening. Truth is I need it to link, but wonder why a custom class does, but not a string...

Code:

Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim list1 As New List(Of String)
        Dim list2 As New List(Of String)

        Dim y As String = "123"

        list1.Add(y)
        list2.Add(y)

        list1(0) = "666"

        MsgBox(list2(0))

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

        Dim list1 As New List(Of Testing)
        Dim list2 As New List(Of Testing)

        Dim y = New Testing
        y.x = "123"

        list1.Add(y)
        list2.Add(y)

        list1(0).x = "666"

        MsgBox(list2(0).x)

    End Sub

    Public Class Testing
        Public Property x As String
    End Class
End Class

Many thanks,#

Viewing all articles
Browse latest Browse all 15743

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>