Advertisement
NAK

VB.NET Pointers

NAK
Jun 23rd, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.81 KB | None | 0 0
  1. Imports System.Runtime.InteropServices
  2.  
  3. Public Class Form1
  4.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  5.  
  6.         Dim gh As GCHandle
  7.         Dim emp As New Employee
  8.         emp.Name = "John"
  9.         emp.Salary = 12345.67
  10.         gh = GCHandle.Alloc(emp)
  11.         Dim emp2 As Employee = gh.Target
  12.         gh.Free()
  13.  
  14.         ' now if you change emp.Salary THEN emp2.Salary is also changed
  15.         emp.Salary = 15000.67 ' set break point on this line and check emp2.Salary
  16.         Dim dbl As Double = emp2.Salary ' step to this line and check emp2.Salary again
  17.         'this demonstrates that emp2 is pointing to emp and any changes to emp are reflected in emp2
  18.     End Sub
  19. End Class
  20.  
  21. Public Class Employee
  22.     Public Name As String
  23.     Public Salary As Decimal
  24. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement