JL.
JL.

Reputation: 81342

C# do const fields use less memory?

Do const fields use less memory than regular variables?

Upvotes: 6

Views: 2824

Answers (1)

user151323
user151323

Reputation:

Const fields memory consumption depends on its usage. The values of const fields are embedded into the IL code during compilation. Without a single reference to a const field there is no memory consumed. When there are many references to the const field, then memory usage may multiply depending on the code portion currently residing in memory.

Upvotes: 4

Related Questions