Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Runtime.InteropServices
- Public Class Form1
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- Dim gh As GCHandle
- Dim emp As New Employee
- emp.Name = "John"
- emp.Salary = 12345.67
- gh = GCHandle.Alloc(emp)
- Dim emp2 As Employee = gh.Target
- gh.Free()
- ' now if you change emp.Salary THEN emp2.Salary is also changed
- emp.Salary = 15000.67 ' set break point on this line and check emp2.Salary
- Dim dbl As Double = emp2.Salary ' step to this line and check emp2.Salary again
- 'this demonstrates that emp2 is pointing to emp and any changes to emp are reflected in emp2
- End Sub
- End Class
- Public Class Employee
- Public Name As String
- Public Salary As Decimal
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement