「VB.NET」Is演算子による同一のインスタンスであるかどうかの比較サンプル

2021年11月29日

書式
インスタンス1 Is インスタンス2
Is演算子を使用して同一のインスタンスであるかどうかの比較を行います

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Module Module1
Public Sub Main()
Dim strA As String = "study"
Dim strB As String = "skill"
'Is演算子
Console.WriteLine("比較結果1: " + (strA Is strB).ToString)
'同一のインスタンスであるかどうかの比較
strA = strB
Console.WriteLine("比較結果2: " + (strA Is strB).ToString)
'等価性の比較ではない
Console.WriteLine("比較結果3: " + (strA Is "study").ToString)
Console.ReadKey()
End Sub
End Module
Module Module1 Public Sub Main() Dim strA As String = "study" Dim strB As String = "skill" 'Is演算子 Console.WriteLine("比較結果1: " + (strA Is strB).ToString) '同一のインスタンスであるかどうかの比較 strA = strB Console.WriteLine("比較結果2: " + (strA Is strB).ToString) '等価性の比較ではない Console.WriteLine("比較結果3: " + (strA Is "study").ToString) Console.ReadKey() End Sub End Module
Module Module1

    Public Sub Main()

        Dim strA As String = "study"
        Dim strB As String = "skill"

        'Is演算子
        Console.WriteLine("比較結果1: " + (strA Is strB).ToString)

        '同一のインスタンスであるかどうかの比較
        strA = strB
        Console.WriteLine("比較結果2: " + (strA Is strB).ToString)

        '等価性の比較ではない
        Console.WriteLine("比較結果3: " + (strA Is "study").ToString)

        Console.ReadKey()
    End Sub

End Module

実行結果
比較結果1: False
比較結果2: True
比較結果3: False

VB.net

Posted by arkgame