Some Data To Work With

   The kind of data that is most appropriate for LINQ To Objects demos is something fairly basic but which still has enough content to be useful for the range of queries I plan to demonstrate. I wanted to stay away from the Products type of data because I want to use that in the LINQ to SQL article (probably utilising Northwind). So in the end I decided on an old favourite for demos - the Person class.

   Here is the class code (which is also available in the downloadable sample zip file).

Public Class Person

 

#Region " Fields"

 

    Private m_forename As String = "No Forename"

    Private m_surname As String = "No Surname"

    Private m_dateofbirth As Date = New Date(1900, 1, 1)

    Private m_gender As Gender = Gender.NotKnown

    Private m_hometown As String = "Not Stated"

    Private m_country As String = "Not Stated"

 

#End Region

 

#Region " Constructors"

 

    '  Base Constructor and one Overloaded Constructor

    '  for example's sake

    Sub New()

        MyBase.New()

    End Sub

 

 

    Sub New(ByVal firstname As String, ByVal lastname As String)

        MyBase.New()

        m_forename = firstname

        m_surname = lastname

    End Sub

 

 

    Sub New(ByVal firstname As String, ByVal lastname As String, ByVal gender As Gender)

        MyBase.New()

        m_forename = firstname

        m_surname = lastname

        m_gender = gender

    End Sub

 

#End Region

 

#Region "Properties"

 

    Public Property Forename() As String

        Get

            Return m_forename

        End Get

        Set(ByVal Value As String)

            m_forename = Value

        End Set

    End Property

 

 

    Public Property Surname() As String

        Get

            Return m_surname

        End Get

        Set(ByVal Value As String)

            m_surname = Value

        End Set

    End Property

 

    Public Property DateOfBirth() As DateTime

        Get

            Return m_dateofbirth

        End Get

        Set(ByVal Value As DateTime)

            If Date.Compare(Value, Now) < 0 Then

                m_dateofbirth = Value

                   Else

                Throw New ArgumentOutOfRangeException("DateOfBirth", _

                   "Future date entered for DateOfBirth.  Value rejected.")

            End If

        End Set

    End Property

 

 

 

    Public Property Gender() As Gender

        Get

            Return m_gender

        End Get

        Set(ByVal Value As Gender)

            m_gender = Value

        End Set

    End Property

 

    Public Property HomeTown() As String

        Get

            Return m_hometown

        End Get

        Set(ByVal value As String)

            m_hometown = value

        End Set

    End Property

 

    Public Property Country() As String

        Get

            Return m_country

        End Get

        Set(ByVal value As String)

            m_country = value

        End Set

    End Property

#End Region

 

#Region " Methods"

 

 

    Public Overrides Function ToString() As String

        Return m_forename & " " & m_surname

    End Function

 

 

 

#End Region

 

End Class

 


I also included an Enumeration of the Gender choices to avoid any problems with typos later:


Public Enum Gender

    Female

    Male

    NotKnown

End Enum