VisualBasic #2:オブジェクト初期化子

2020年9月13日日曜日

C# VisualBasic

t f B! P L
オブジェクト初期化子とは?
前回記事:VisualBasic #1:App.Pathを取得するには


オブジェクトの生成と同時にプロパティの設定が可能
例えば:
Dim obj As TestClass = New TestClass()
With obj
  .PropA = 1
  .PropB = 2
End With
とするところを、
Dim obj As TestClass = New TestClass() With {.PropA = 1, .PropB = 2}
と書ける。

C#の場合は以下のようになる。
var obj = new TestClass() {ProcA = 1, ProcB  =2};





次回記事:VisualBasic #3:数値型への変換


VisualBasic学習, C#学習

その他の記事

QooQ