LoginSignup
1
0

More than 3 years have passed since last update.

【VB.net】Listの初期化と代入方法 色々な書き方

Posted at

VB.netのListを調べてたら色々な初期化と代入方法に遭遇したので
書き残しておこうと思います。

空リストの作成

Dim list1 As List(Of String) = New List(Of String)()
'後ろの()は省略可
Dim list2 As List(Of String) = New List(Of String)

Dim list3 As New List(Of String)

Dim list4 = New List(Of String)

イマイチ差が分かりませんでしたが、人によって使用しているパターンに違いがありました。

リスト作成&代入

上のリスト作成時の記述につなげて書けば良い

ただし()を使うかFromを使うかの2パターンあるよう

パターン1 ()の場合

({要素1, 要素2, 要素3})をList作成時の記述につなげる

Dim list1 As List(Of String) = New List(Of String)({"a", "b", "c"})

Dim list3 As New List(Of String)({"a", "b", "c"})

Dim list4 = New List(Of String)({"a", "b", "c"})

パターン2 Fromの場合

From {要素1, 要素2, 要素3}をList作成時の記述につなげる

Dim list1 As List(Of String) = New List(Of String) From {"a", "b", "c"}

Dim list3 As New List(Of String) From {"a", "b", "c"}

Dim list4 = New List(Of String) From {"a", "b", "c"}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0