本文整理汇总了VB.NET中System.ParamArrayAttribute类的典型用法代码示例。如果您正苦于以下问题:VB.NET ParamArrayAttribute类的具体用法?VB.NET ParamArrayAttribute怎么用?VB.NET ParamArrayAttribute使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ParamArrayAttribute类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: New
Public Class Temperature
Private temp As Decimal
Public Sub New(temperature As Decimal)
Me.temp = temperature
End Sub
Public Overrides Function ToString() As String
Return ToString("C")
End Function
Public Overloads Function ToString(format As String) As String
If String.IsNullOrEmpty(format) Then format = "G"
Select Case format
Case "G", "C"
Return temp.ToString("N") + " °C"
Case "F"
Return (9 * temp / 5 + 32).ToString("N") + " °F"
Case "K"
Return (temp + 273.15d).ToString("N") + " °K"
Case Else
Throw New FormatException(String.Format("The '{0}' format specifier is not supported", _
format))
End Select
End Function
Public Sub Display(<[ParamArray]()> formats() As String)
If formats.Length = 0 Then
Console.WriteLine(Me.ToString("G"))
Else
For Each format As String In formats
Try
Console.WriteLine(Me.ToString(format))
' If there is an exception, do nothing.
Catch
End Try
Next
End If
End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System,代码行数:41,代码来源:ParamArrayAttribute
示例2: Main
Public Module Example
Public Sub Main()
Dim temp1 As New Temperature(100)
Dim formats() As String = { "C", "G", "F", "K" }
' Call Display method with a string array.
Console.WriteLine("Calling Display with a string array:")
temp1.Display(formats)
Console.WriteLine()
' Call Display method with individual string arguments.
Console.WriteLine("Calling Display with individual arguments:")
temp1.Display("C", "F", "K", "G")
Console.WriteLine()
' Call parameterless Display method.
Console.WriteLine("Calling Display with an implicit parameter array:")
temp1.Display()
End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:20,代码来源:ParamArrayAttribute 输出:
Calling Display with a string array:
100.00 °C
100.00 °C
212.00 °F
373.15 °K
Calling Display with individual arguments:
100.00 °C
212.00 °F
373.15 °K
100.00 °C
Calling Display with an implicit parameter array:
100.00 °C
注:本文中的System.ParamArrayAttribute类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论