[VB.NET]構造体(Enum)でメソッド(Function)を使うサンプル
書式
Function メソッド名()
構造体のオブジェクト名.メソッド名
使用例
'構造体の定義
Structure Sample
Public userId As Integer
Public name As String
'メソッドの定義
Function GetName()
Return "this is a test message"
End Function
End Structure
Module ModuleTest
Sub Main()
Dim cft As New Sample
'構造体のメソッドを実行して値を表示
Console.WriteLine(cft.GetName)
End Sub
End Module
'構造体の定義
Structure Sample
Public userId As Integer
Public name As String
'メソッドの定義
Function GetName()
Return "this is a test message"
End Function
End Structure
Module ModuleTest
Sub Main()
Dim cft As New Sample
'構造体のメソッドを実行して値を表示
Console.WriteLine(cft.GetName)
End Sub
End Module
'構造体の定義 Structure Sample Public userId As Integer Public name As String 'メソッドの定義 Function GetName() Return "this is a test message" End Function End Structure Module ModuleTest Sub Main() Dim cft As New Sample '構造体のメソッドを実行して値を表示 Console.WriteLine(cft.GetName) End Sub End Module
実行結果
this is a test message