Attributes in C#

前端 未结 8 742
时光说笑
时光说笑 2020-11-30 04:08

I know that C# (and .NET in general) is big on attributes. However, despite the fact I have programmed in C# for many years, I haven\'t found myself ever using them. Would s

8条回答
  •  爱一瞬间的悲伤
    2020-11-30 04:26

    Attributes get more use in code targeted to other programmers or between distinct parts of a program, rather than code targeted at end users.

    For example, you could use attributes to import a dll, indicate how types would interact with visual studio (designer visible, intellisense helps, debugger step-through, etc), how to serialize them, indicate a type is obsolete, describe default values, descriptions, handle COM access, etc.

    Those are things that are largely invisible to the end user and that a single programmer could put elsewhere in the source code. But they're useful when only the compiled binary is available and not the source.

提交回复
热议问题