LoginSignup
8
9

More than 5 years have passed since last update.

みんなー、VB.Net でも Extensions でけたよー

Posted at

VB.Net でもやりてー!ということでググってみると、できるみたい。

書いてみた

Imports System.Runtime.CompilerServices

Public Module StringExntensions
    <Extension()>
    Public Function IsNullOrEmpty(ByVal this As String) As Boolean
        Return String.IsNullOrEmpty(this)
    End Function

    <Extension()>
    Public Function IsNullOrWhiteSpace(ByVal this As String) As Boolean
        Return String.IsNullOrWhiteSpace(this)
    End Function

    <Extension()>
    Public Function Format(ByVal this As String, ByVal ParamArray args() As Object) As String
        Return String.Format(this, args)
    End Function
End Module
Module Module1
    Sub Main()
        Console.WriteLine("Test1=" & "".IsNullOrEmpty())
        Console.WriteLine("Test2=" & "".IsNullOrWhiteSpace())
        Console.WriteLine("{0} & {1}".Format(2, 3))
        Console.ReadLine()
    End Sub
End Module
Test1=True
Test2=True
2 & 3

やればできるんだよ、あきらめるなよ、もっと熱くなれよ!

8
9
1

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
8
9