Simple Structure Demo : Structure « Language Basics « VB.Net

Simple Structure Demo

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"

    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
            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


Related examples in the same category

1.Structure Variable assignment
2.ToString Method for Structure data typeToString Method for Structure data type
3.Structure overrides ToString method
4.Structure with Constructor
5.Store Structure into a Collection
6.Compare Structure and ClassCompare Structure and Class
7.Pass Structure into a FunctionPass Structure into a Function
8.ValueType.Equals Method Indicates whether this instance and a specified object are equal.