Method Signatures

Hello there,

Is it possible to have in Xojo two methods like this

Sub query(name As String)  return Employe()
Sub query(surname As String) return Employe()

How implement it, how call it ? Something like this ?

Var Xo() As Employe = mydata.query(name: "XO")
Var Jo() As Employe = mydata.query(surname: "JO")

From what I recall, only if the calling sequences differ. Otherwise the compiler can’t distinguish between them.

Hi Sebastien!
You can overload methods, but the parameters must be different. Your proposed methods won’t work as they both take a single string parameter and return an Employe. You should use different method names in this case:

Sub queryFirst(name As String) As Employe()
Sub querySur(surname As String) As Employe()

Or add a parameter for distinction:

Sub query(name As String, isSurname as Boolean = False) As Employe()
1 Like

Thank you @Anthony_G_Cyphers and @TimStreater, I will do something like this:

Sub query(row As String, value As String) As Employe()