Imports System
Public Enum Country
US = 1
CA = 2
End Enum
Public Class AClass
Public Name As String
Public Status As Country
End Class
Public Structure AStruct
Public Name As String
Public Status As Country
End Structure
Public Module Test
Public Sub ChangeName_Obj_ByVal(ByVal details As AClass,ByVal NewName As String)
details.Name = NewName
End Sub
Public Sub ChangeName_Obj_ByRef(ByRef details As AClass,ByVal NewName As String)
details.Name = NewName
End Sub
Public Sub ChangeName_Struct_ByVal(ByVal details As AStruct,ByVal NewName As String)
details.Name = NewName
End Sub
Public Sub ChangeName_Struct_ByRef(ByRef details As AStruct,ByVal NewName As String)
details.Name = NewName
End Sub
Sub Main()
Dim classInstance As AClass = New AClass()
Dim structInstance As AStruct = New AStruct()
classInstance.Name = "A"
classInstance.Status = Country.CA
structInstance.Name = "B"
structInstance.Status = Country.CA
Console.WriteLine("{0}, {1}", classInstance.Name, classInstance.Status)
Console.WriteLine("{0}, {1}", structInstance.Name, structInstance.Status)
Console.WriteLine()
ChangeName_Obj_ByVal(classInstance, "AAAA")
ChangeName_Struct_ByVal(structInstance, "BBBB")
Console.WriteLine("{0},{1}", classInstance.Name, classInstance.Status)
Console.WriteLine("{0},{1}", structInstance.Name, structInstance.Status)
Console.WriteLine()
ChangeName_Obj_ByRef(classInstance, "AAAA")
ChangeName_Struct_ByRef(structInstance, "BBBB")
Console.WriteLine("{0}, {1}", classInstance.Name, classInstance.Status)
Console.WriteLine("{0}, {1}", structInstance.Name, structInstance.Status)
End Sub
End Module
|