Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an additional runtime cost for using named parameters?

Tags:

c#-4.0

Consider the following struct:

    public struct vip
    {
        string email;
        string name;
        int category;

        public vip(string email, int category, string name = "")
        {
            this.email = email;
            this.name = name;
            this.category = category;
        }
    }

Is there a performance difference between the following two calls?

var e = new vip(email: "foo", name: "bar", category: 32);

var e = new vip("foo", 32, "bar");

Is there a difference if there are no optional parameters defined?

like image 314
György Andrasek Avatar asked Jan 29 '26 16:01

György Andrasek


1 Answers

I believe none. It's only a language/compiler feature, call it syntactic sugar if you like. The generated CLR code should be the same.


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!