[VB.NET]構造体(Enum)でメソッド(Function)を使うサンプル

2021年4月20日

書式
Function メソッド名()
構造体のオブジェクト名.メソッド名
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
'構造体の定義
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

VB.net

Posted by arkgame