我具有以下功能:
Private Sub AddToEventDetails(ByRef sEvent As My_GoogleEvent, strLabelID As String, ByRef dictLabels As Dictionary(Of String, String), strValue As String)
Dim strFormatString = dictLabels(strLabelID)
Dim strText = String.Format(strFormatString, strValue)
' strText can never be empty because it now includes the label. So test against strValue instead
If (strValue <> "") Then
sEvent.strEventDetails += strText & vbCrLf
End If
End Sub
Private Sub AddToEventDetails(ByRef sEvent As My_GoogleEvent, strLabelID As String, ByRef dictLabels As Dictionary(Of String, String), strValue1 As String, strValue2 As String)
Dim strFormatString = dictLabels(strLabelID)
Dim strText = String.Format(strFormatString, strValue1, strValue2)
If (strText <> "") Then
sEvent.strEventDetails += strText & vbCrLf
End If
End Sub
Private Sub AddToEventDetails(ByRef sEvent As My_GoogleEvent, strLabelID As String, ByRef dictLabels As Dictionary(Of String, String), strValue1 As String, strValue2 As String, strValue3 As String)
Dim strFormatString = dictLabels(strLabelID)
Dim strText = String.Format(strFormatString, strValue1, strValue2, strValue3)
If (strText <> "") Then
sEvent.strEventDetails += strText & vbCrLf
End If
End Sub
Private Sub AddToEventDetails(ByRef sEvent As My_GoogleEvent, strLabelID As String, ByRef dictLabels As Dictionary(Of String, String), strValue1 As String, strValue2 As String, strValue3 As String, strValue4 As String)
Dim strFormatString = dictLabels(strLabelID)
Dim strText = String.Format(strFormatString, strValue1, strValue2, strValue3, strValue4)
If (strText <> "") Then
sEvent.strEventDetails += strText & vbCrLf
End If
End Sub
Private Sub AddToEventDetails(ByRef sEvent As My_GoogleEvent, strLabelID As String, ByRef dictLabels As Dictionary(Of String, String), strValue1 As String, strValue2 As String, strValue3 As String, strValue4 As String, strValue5 As String)
Dim strFormatString = dictLabels(strLabelID)
Dim strText = String.Format(strFormatString, strValue1, strValue2, strValue3, strValue4, strValue5)
If (strText <> "") Then
sEvent.strEventDetails += strText & vbCrLf
End If
End Sub
它们非常简单,可以正常工作。我只是想知道是否有一种不知道这些功能可以在哪里合并的简单方法?
您可以看到主要区别在于:
String
个参数的数量。String.Format
函数的变量。现在,我意识到我可以设置String
参数optional
并将其默认设置为""
,然后可以使用if\else
梯形图或switch
。但是对于这种事情还有其他方法吗?
谢谢。