لو كنت قد جربت التعامل مع الثوابت بكثرة ، فلا بد انك تساءلت ، ما هو الفارق بين تعريف ثابت const او تعريفه باستخدام static readonly ، فكلاهما كما تعلم لا يمكن تغيير قيمتهما . الفارق بسيط جداً ، هو ان ال const يتم تعريف قيمتها وقت ال compile time ، اما قيمة ال static readonly فيتم تعريفها وقت ال run time . لهذا سنجد مزية اضافية لل static readonly ، وهو اننا يمكن ان نقوم بتعريفة في ال static constructor بالشكل التالي مثلاً : class Program { public static readonly Test test = new Test(); static void Main(string[] args) { test.Name = "Program"; } | التسميات: C#, Tips And Tricks |
Scope and Accessibility in Class Modules
The .NET Framework: General Concepts
Namespaces
Common Language Runtime (CLR), Managed Code, and Managed Data
Managed Execution
Assemblies
Assemblies and VB .NET
The .NET Framework Class Library
The System Namespace
Other Namespaces
Delegates and Events
Delegates
Events and Event Binding
Error Handling in VB .NET
Error Detection and Error Handling
Runtime Error Handling
Dealing with Logical Errors
Error Constants
The Language Reference
#Const Directive