I am trying to call the following function:
public void seleccionarpanelsecundario([Optional, DefaultParameterValue(null)] ref TabPage a, [Optional, DefaultParameterValue(false)] bool regresaralpaneldeterminado) // cambia el panel secundario a travez de tabitem
{
And what I want to do is call it only the second parameter. In the following way:
seleccionarpanelsecundario(, true);
and it tells me that an argument is missing, but it's optional.
In another case I try to call a function where it also sent a parameter, of which it is optional as follows. I have the following function:
public string rellenarlistadetickets(string iniciofecha, string finfecha, [Optional, DefaultParameterValue(0)] ref decimal total, bool obtenerdecajaabierta = false)
{
And I call it in the following way and it also gives me an error:
console.writeline(ticketaanular.rellenarlistadetickets(desde.Text, desde.Text, obtenerdecajaabierta: true))
In the latter, the following poster tells me:
How can I achieve what I'm trying to do, call a function while avoiding an optional parameter?
Let's go case by case...
In the first case, of course it's optional...
But since all parameters are optional, the compiler is inferring that yours is an error. He is wrong, you were not mistaken, but how can he know?
If you want to call it only with the second parameter, either you send the first one with its default value... or you pass named parameters to it.(parametername: value)
In the second case, the last two parameters are optional. (note: I don't know what is defined like this: [Optional, DefaultParameterValue(0)]). By putting parameter = value, you are already declaring it optional.
But... since I don't understand that way of defining optional parameters, it seems that the compiler doesn't either, because when displaying the function signature, it doesn't appear as optional. That's why you can't call the last one positionally, because you're missing a formal parameter of the function...