Steven Giesel 8/21/2023

Expression-bodied members in properties

Read Original

This technical article clarifies a key C# concept: the difference between a property with a getter initializer (`public int A { get; } = ...`) and an expression-bodied property (`public int B => ...`). It demonstrates that the initializer evaluates once at creation, while the expression-bodied member is evaluated on every access, using code examples and lowered IL to illustrate the behavior.

Expression-bodied members in properties

Comments

No comments yet

Be the first to share your thoughts!

Browser Extension

Get instant access to AllDevBlogs from your browser

Top of the Week

1
The Beautiful Web
Jens Oliver Meiert 2 votes
3
LLM Use in the Python Source Code
Miguel Grinberg 1 votes
4
Wagon’s algorithm in Python
John D. Cook 1 votes