Muhammad Waseem Profile picture
Senior Software Engineer (.NET) | Tweets and threads are related to C# and .NET

May 13, 2023, 8 tweets

What is the difference b/w field and property , what are the different types of properties in C# ?

- Properties
- Field vs Properties
- 6 Types of Properties

#dotnet

Properties vs Field

- Properties are first class citizens in C#
- We used properties to achieve abstraction
- Properties are implemented via accessors
- Enable developers to write code that accurately expresses their design intent
#dotnet

Read only Properties

- Serve the purpose of getters
- Use them for retrieving the information in DTO
- We can not set them

#dotnet

Write only Properties
- Serve the purpose of setters
- We can not use them for reading the data
#dotnet

Auto Implemented Properties
- Use them as setter/getter
- Most simple form of properties

#dotnet

Required properties
- Used for validation purpose 
- To make sure that required properties are present

#dotnet

Init only Properties
- Used to set the data
- One can set data only during object initialization
- Helpful in creating read-only properties

#dotnet

If you like it , you might be interested in my weekly .NET Newsletter.
Join with 2500+ here : lnkd.in/dNHxJGRG

#dotnet

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling