Mega Code Archive

 
Categories / VB.Net / Language Basics
 

Simple Structure Demo

Imports System Public Class MainClass     Shared Sub Main()         'Declare a Customer object         Dim objNewCustomer As Customer         'Create the new customer         objNewCustomer.FirstName = "f"         objNewCustomer.LastName = "l"         objNewCustomer.Email = "e"                  System.Console.WriteLine(objNewCustomer)     End Sub End Class Public Structure Customer     'Public members     Public FirstName As String     Public LastName As String     Public Email As String     'Name property     Public ReadOnly Property Name() As String         Get             Return FirstName & " " & LastName         End Get     End Property     ''' <summary>     ''' Overrides the default ToString method     ''' </summary>     ''' <returns>String</returns>     ''' <remarks>Returns the customer name and email address</remarks>     Public Overrides Function ToString() As String         Return Name & " (" & Email & ")"     End Function End Structure