Is there any difference between named arguments and default constructor arguments for an attribute?

Is there any difference between these attributes? Is one better to use than the other?

[AttributeUsage(AttributeTargets.Class)]
public class CustomAttribute : System.Attribute
{
    public string Name { get; }

    public CustomAttribute(string name = "")
    {
        Name = name;
    }
}

[AttributeUsage(AttributeTargets.Class)]
public class CustomNonDefaultAttribute : System.Attribute
{
    public string Name { get; set; } = "";
}

[Custom(name: "sdfsd")]
[CustomNonDefault(Name = "sdfsd")]
public class MyClass
{
}
Was this page helpful?