Error: cannot overload each other because they differ only by optional parameters.
One method has 3 parameters and the other has 4 parameters. What am I missing?
Protected Overloads Function updateResxNodes(ByVal keyCtrl As String, ByVal newValue As String, Optional ByVal newComment As String = "") As List(Of ResXDataNode)
Dim resxNodesList As List(Of ResXDataNode) = getResourceData()
For i As Integer = 0 To resxNodesList.Count - 1
If resxNodesList.Item(i).Name = keyCtrl Then
Dim name As String = resxNodesList.Item(i).Name
Dim comment As String = resxNodesList.Item(i).Comment
Dim newResxNode As ResXDataNode = New ResXDataNode(name, newValue)
newResxNode.Comment = comment
resxNodesList.RemoveAt(i)
resxNodesList.Add(newResxNode)
Exit For
End If
Next
Return resxNodesList
End Function
Protected Overloads Function updateResxNodes(ByVal keyCtrl As String, ByVal newName As String, ByVal newValue As String, Optional ByVal newComment As String = "") As List(Of ResXDataNode)
Dim resxNodesList As List(Of ResXDataNode) = getResourceData()
For i As Integer = 0 To resxNodesList.Count - 1
If resxNodesList.Item(i).Name = keyCtrl Then
Dim name As String = resxNodesList.Item(i).Name
Dim comment As String = resxNodesList.Item(i).Comment
Dim newResxNode As ResXDataNode = New ResXDataNode(name, newValue)
newResxNode.Comment = comment
resxNodesList.RemoveAt(i)
resxNodesList.Add(newResxNode)
Exit For
End If
Next
Return resxNodesList
End Function
The optional parameters are confusing the compiler on which function it should use.
Also, the compiler can’t differentiate the newValue and newName parameters between the two functions because they are both strings in the second slot.
You aren’t using newName in your second function– does that belong there?
You might want to consider something like this: