「VB.NET」構造体(Structure)のサンプル

2021年10月1日

書式

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Structure 構造体
  Public 変数名 As データ型
End Structure
Structure 構造体   Public 変数名 As データ型 End Structure
Structure 構造体
  Public 変数名 As データ型
End Structure

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Module Module1
'構造体Customerの定義
Structure Customer
'String型変数の宣言
Public userName As String
'Integer型変数の宣言
Public age As Integer
'Boolean型変数の宣言
Public flg As Boolean
End Structure
Sub Main()
'構造体の変数cst
Dim cst As New Customer
'構造体の変数に値を設定
cst.userName = "テスト太郎"
cst.age = 32
cst.flg = False
'構造体の値を表示
Console.WriteLine(cst.userName)
Console.WriteLine(cst.age)
Console.WriteLine(cst.flg)
Console.ReadKey()
End Sub
End Module
Module Module1 '構造体Customerの定義 Structure Customer 'String型変数の宣言 Public userName As String 'Integer型変数の宣言 Public age As Integer 'Boolean型変数の宣言 Public flg As Boolean End Structure Sub Main() '構造体の変数cst Dim cst As New Customer '構造体の変数に値を設定 cst.userName = "テスト太郎" cst.age = 32 cst.flg = False '構造体の値を表示 Console.WriteLine(cst.userName) Console.WriteLine(cst.age) Console.WriteLine(cst.flg) Console.ReadKey() End Sub End Module
Module Module1
    '構造体Customerの定義
    Structure Customer

        'String型変数の宣言
        Public userName As String

        'Integer型変数の宣言
        Public age As Integer

        'Boolean型変数の宣言
        Public flg As Boolean

       

    End Structure

    Sub Main()

        '構造体の変数cst
        Dim cst As New Customer

        '構造体の変数に値を設定
        cst.userName = "テスト太郎"
        cst.age = 32
        cst.flg = False

        '構造体の値を表示
        Console.WriteLine(cst.userName)
        Console.WriteLine(cst.age)
        Console.WriteLine(cst.flg)

        Console.ReadKey()

    End Sub

End Module

実行結果
テスト太郎
32
False

VB.net

Posted by arkgame