LoginSignup
7
6

More than 5 years have passed since last update.

Visual Basic 14.0の新機能

Last updated at Posted at 2015-02-09

簡潔に紹介していくよ!

Getterのみの自動実装プロパティ

英語名:Getter-only auto properties

Public ReadOnly Property Y As Integer = 10

今までは、プロパティと定数で分離する必要がありましたが、プロパティだけでできるようになりました。

コンストラクタ内での、ReadOnlyのプロパティへ割り当て

英語名:Assignment to readonly autoprops in constructors

パラメータを持たない構造体のコンストラクタ

英語名:Parameterless constructors in structs

上2つの例

Public Structure S 
   Public ReadOnly Property x As Integer
   Public Property y As Integer

   Public Sub New()
      x = 15
      y = 23
   End Sub
End Structure

部分的モジュール・インターフェース(Partial Module/Inteface)

例を示さなくてもわかるので、省略します。

文字列を改行するリテラル(C#でいう、\n)

英語名:Multiline string literals
修正しました

"あいうえお" & Environment.NewLine & "かきくけこ" & Environment.NewLine & "さしすせそ"

と書いていたのを、

"あいうえお
かきくけこ
さしすせそ"

と書けるようになったってこと

日付リテラル(C#にはない!)

英語名:Year-first date literals

#2014-03-12#
#2016-11-23 12:30#
#2015-07-18 4:20 PM#

上の3つの書き方が可能なようです。

LINQなどの構文で改行したところにもコメントが書けるようになる

英語名:Line continuation comments

Dim invitees = {"Jim",    ' got to invite him!
                "Marcy",  ' Jim's wife
                "Jones"}

Dim addresses = From i In invitees      ' go through list
                Let address = Lookup(i) ' look it up
                Select i, address

そんなところにコメントを書いても怒られなくなりました。

TypeOf IsNot

英語名:そのまま

Dim x As Boolean = Not(TypeOf y Is Integer)

というコードを、

Dim x As Boolean = TypeOf y IsNot Integer

と書けるようになりました。

Null条件演算子

英語名:Null-conditional operators

customer.Address?.Country

文字列補間

英語名:String interpolation

$"Now: {DateTime.Now :f}"

ちなみに以下の様なことはできません。

"Now: \{DateTime.Now : f}"

NameOf

Dim x As String = NameOf(System.Console) 'x = "System.Console"

C#と全く同じですね。

コンパイラが賢くクラス名・関数名を判別するように

Imports System
Imports System.Windows

REM 途中省略

Threading.Thread.Sleep(1000)
'ちゃんと判別されるように!

StructureでNew()をかけるように

Friend Structure Hoge
   Friend N As Integer
   Sub New()
      N = 0
   End Sub
End Structure

#Enable/Disable Warning

以下のようにワーニングを無効化・有効化することができるようになりました.

#Disable Warning BCM00000
#Enable Warning BCM00000

その他

#Regionがメソッド内に書くことができたりするようになりました。
詳しくはこちらを…

7
6
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
7
6