I've got this method, which I don't understand.. I tried searching for it but since I didn't really know what to search for I didn't find anything.
Can somebody please explain it to me?
public List<listElementType> Search(string name,
bool onlyActive = true,
bool onlyDeleted = true,
decimal from = 0,
decimal to = decimal.MaxValue)
{
// Some SQL stuff
return ...;
}
And why can I use it like I mentioned in the title?
Search(name, onlyActive: true);
It's a named argument, it's calling the method Search with name = name and onlyActive = true.
It's actually doing the exact same thing as calling
Search(name);
You can use them on methods to specify the argument you want to change, effectively allowing us to skip default arguments. For example:
Search(name, from: 1, to: 2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With