tagCANDY CGI VBレスキュー(花ちゃん) の Visual Basic 2010 用 掲示板(VB.NET 掲示板)
VBレスキュー(花ちゃん) の Visual Basic 2010 用 掲示板(VB.NET 掲示板)
[ツリー表示へ]  [ワード検索]  [Home]

タイトル Re^3: tostringを改良したい
投稿日: 2012/08/14(Tue) 17:02
投稿者魔界の仮面弁士
> Debug.Print (FormatNumber(x,3) & "   " & FormatNumber(y,4))
> というように「"   " &」を余分に書かねばならないので,
Debug.Print(書式, x, y) や Console.WriteLine(書式, x, y)、
String.Format(書式, x, y) などでは駄目なのでしょうか?


>>それを嫌う場合にはジェネリックを使わず、Double/Integer などといった
>>個々の型に対するオーバーロードを実装
> という方法も教えて頂けないでしょうか?

Module Sigechin
    <System.Runtime.CompilerServices.Extension()> _
    Public Function ToStringF(value As Double, a As Byte, b As Byte) As String
        Return String.Format("{0," & CStr(a) & ":F" & CStr(b) & "}", value)
    End Function

    <System.Runtime.CompilerServices.Extension()> _
    Public Function ToStringF(value As Integer, a As Byte, b As Byte) As String
        Return String.Format("{0," & CStr(a) & ":G" & CStr(b) & "}", value)
    End Function

    <System.Runtime.CompilerServices.Extension()> _
    Public Function ToStringF(value As Decimal, ……
    '以下同様に、Decimal, Single, Byte, SByte, Short, UShort,
    '      UInteger, Long, ULong, BigInteger 等のためのメソッドを用意。
End Module

- 関連一覧ツリー をクリックするとツリー全体を一括表示します)

古いスレッドにレスはつけられません。