© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
2 replies
nathanAjacobs

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
{
}
[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
{
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Is there any difference between `[Route("")]` and `[Route("/")]`?
C#CC# / help
3y ago
Is there any difference between visual studio code and community?
C#CC# / help
2y ago
❔ what is difference between _ and ()?
C#CC# / help
3y ago