Showing posts with label local variables. Show all posts
Showing posts with label local variables. Show all posts

Pain in the m_*!@#$

Everytime I do work for a client that has internal coding standards I find myself having to change between using the letter "m" or an underscore "_" or, God forbid, both of them "m_", when I need to name some variable that has a public property associated with it.

Here is what I consider to be a better fourth option. Enclose all of your backing variables into a structure. Then create a single instance of that structure and store it in a private variable called "Local".

It's easy to do, easy to read/write and provides a single method that works for everyone.


Public Class Employee
  
    Private Structure backingStore
        Public firstName As String
        Public lastName As String
    End Structure

    Private Local As New backingStore

    Public Property FirstName() As String
        Get
            Return Local.firstName
        End Get
        Set(ByVal value As String)
            Local.firstName = value
        End Set
    End Property

    End Class


Read more...