Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#

Predefined Attributes ใน C# (Attributes ที่มีอยู่สำเร็จ)

Predefined Attributes ใน C# มี 3 ตัว:

  • AttributeUsage
  • Conditional
  • Obsolete

AttributeUsage

อธิบายว่า Custom Attribute Class ใช้ได้อย่างไร Syntax:

[AttributeUsage(validon, AllowMultiple = allowmultiple, Inherited = inherited)]

Conditional

Mark Method ว่า Conditional Execution ขึ้นอยู่กับ Preprocessing Identifier ใช้สำหรับ Conditional Compilation (Debug/Trace)

[Conditional(conditionalSymbol)]

Obsolete

Mark Program Entity ว่าไม่ควรใช้ แจ้ง Compiler ให้ Discard Target Element

[Obsolete(message)]
[Obsolete(message, iserror)]