why we use description attribute for class property in c#

2.1k Views Asked by At

i saw in some code that use Description attribute for class property and i couldn't find reason of behavior in c# codding

 public class sample
    {
        [Description("description1")]
        public string PropertyOnne{ get; set; }

     }

for readability of code we can use xml summary for even property and i didn't understand what is difference between summary and Description attribute in class level.

2

There are 2 best solutions below

0
On BEST ANSWER

Simple words, you can consider below explanation

  • The tag is used to generate documentation in XML for your Project at Compile time, this is also used by the visual studio for its intellisense database

  • The Description attribute used by the designer in order to understand the text, mostly at the bottom of the property window(for reference).

0
On

This is for visual designers, they can display the description when referencing them.

Remark from the docs:

A visual designer can display the specified description when referencing the component member, such as in a Properties window. Call Description to access the value of this attribute.

Source: https://learn.microsoft.com/en-us/dotnet/api/system.componentmodel.descriptionattribute?view=netframework-4.7.2