Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the ":" mean in Search(name, onlyActive: true)?

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);
like image 409
dga Avatar asked Nov 26 '25 16:11

dga


1 Answers

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);
like image 158
Daniel Imms Avatar answered Nov 28 '25 16:11

Daniel Imms



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!