title: ByRef vs ByVal Clarification
body: <p>I'm just starting on a class to handle client connections to a TCP server.  Here is the code I've written thus far:</p>
  
  <pre><code>Imports System.Net.Sockets
  Imports System.Net
  
  Public Class Client
      Private _Socket As Socket
  
      Public Property Socket As Socket
          Get
              Return _Socket
          End Get
          Set(ByVal value As Socket)
              _Socket = value
          End Set
      End Property
  
      Public Enum State
          RequestHeader ''#Waiting for, or in the process of receiving, the request header
          ResponseHeader ''#Sending the response header
          Stream ''#Setup is complete, sending regular stream
      End Enum
  
      Public Sub New()
  
      End Sub
  
      Public Sub New(ByRef Socket As Socket)
          Me._Socket = Socket
  
      End Sub
  End Class
  </code></pre>
  
  <p>So, on my overloaded constructor, I am accepting a <em>reference</em> to an <em>instance</em> of a <code>System.Net.Sockets.Socket</code>, yes?</p>
  
  <p>Now, on my <code>Socket</code> property, when setting the value, it is required to be <code>ByVal</code>.  It is my understanding that the <em>instance</em> in memory is <em>copied</em>, and this <em>new instance</em> is passed to <code>value</code>, and my code sets <code>_Socket</code> to reference this instance in memory.  Yes?</p>
  
  <p>If this is true, then I can't see why I would want to use properties for anything but native types.  I'd imagine there can be quite a performance hit if copying class instances with lots of members.  Also, for this code in particular, I'd imagine a copied socket instance wouldn't really work, but I haven't tested it yet.</p>
  
  <p>Anyway, if you could either confirm my understanding, or explain the flaws in my foggy logic, I would greatly appreciate it.</p>