LoginSignup
7
7

More than 5 years have passed since last update.

VisualBasic .net 15 の新機能

Last updated at Posted at 2016-10-13

環境

VisualStudio 2017.1
Visual Basic Compiler 2.1.0.61520
Windows 10 Creators Update

Binary Literals (バイナリ表記のリテラル)

1と0(2進数)を用いて値が表せるになりました.

Dim i As Integer = &B1101
Console.WriteLine(i) ' → 13

Digit Separators (桁区切り)

'_' をもちいて桁区切りができるようになりました.

Dim d As Integer = &B11___0_1
Console.WriteLine(i)

Tuples(タプルの言語サポート強化)

この機能は,System.Tupleではなくて,System.ValueTupleのみに使えるものです.
ターゲットフレームワークが.Net 4.7であれば,何も作業する必要はありませんが,それ以前のバージョンでは,Nugetから System.ValueTuple を導入する必要があります.

クリップボード01.jpg

具体的には,以下のように書けます.

Module Module1
    Sub Main()
        Dim point As (x As Integer, y As Integer) = GetPoint()
        Console.WriteLine(point.x)
        Console.WriteLine(point.Item1) '旧来のメンバ名でもおk
    End Sub
    Function GetPoint() As (x As Integer, y As Integer)
        Return (12, 20)
    End Function
End Module
7
7
2

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
7