Muhammad Waseem Profile picture
May 13, 2023 8 tweets 4 min read Read on X
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 Image
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 Image
Read only Properties

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

#dotnet Image
Write only Properties
- Serve the purpose of setters
- We can not use them for reading the data
#dotnet Image
Auto Implemented Properties
- Use them as setter/getter
- Most simple form of properties

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

#dotnet Image
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

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Muhammad Waseem

Muhammad Waseem Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @mwaseemzakir

Aug 2, 2023
Multiple ways to create middleware in .NET?

It is software assembled into an app pipeline to handle requests and responses. In simple, it gives us the facility to add additional logic before and after the HTTP request.

𝗛𝗼𝘄 𝗱𝗼𝗲𝘀 𝗺𝗶𝗱𝗱𝗹𝗲𝘄𝗮𝗿𝗲 𝘄𝗼𝗿𝗸 👇 Image
Suppose we have three middleware in our app then for each middleware we enter two times.

First middleware logic is performed then we send it to the next middleware Image
Secondly when a request comes back after executing the next middleware

𝗧𝗵𝗿𝗲𝗲 𝘄𝗮𝘆𝘀 𝘁𝗼 𝗰𝗿𝗲𝗮𝘁𝗲 𝗺𝗶𝗱𝗱𝗹𝗲𝘄𝗮𝗿𝗲:
- Request delegate
- By convention
- Using middleware factory

Let's dive how to implement them :
Read 8 tweets
Jun 26, 2023
What is SOLID , why we need these principles and S explained ?
It is combination of 5 design principles
S - Single Responsibility Principle (SRP)
O - Open/Closed Principle (ORP)
L - Liskov Substitution Principle (LSP)
I - Interface Segregation Principle (ISP)

Thread 🧵👇
D - Dependency Inversion Principle (DIP)

Why we need SOLID or its benefits
- Better Testability
- Reduces coupling
- Removes Duplication
- Increases Readability
- Increases Extensibility

SRP says :-
- A class/method should have one reason to change
- A class/method should have only one responsibility
- A class/method should be related to a single purpose

With SRP we achieve :-
- Class/method becomes smaller and cleaner
- Now in future updating the code becomes easier

Example
Read 9 tweets
Jun 20, 2023
Are you struggling to find right resources to learn C# and .NET then check these out ?

𝐘𝐨𝐮𝐓𝐮𝐛𝐞 𝐂𝐡𝐚𝐧𝐧𝐞𝐥𝐬
- Dotnet (bit.ly/3L2CUqn)
- Edureka (bit.ly/3GLdT0k)
- Brackeys (bit.ly/3zYDMWA)
- Kudvenkat (bit.ly/3MGsSfK)🧵👇

#dotnet
- QuestPond (bit.ly/3N303KP)
- Nick Chapsas (bit.ly/3MKFhiz)
- Derek Banas (bit.ly/41wU9FM)
- Milan Jovanović (bit.ly/3zXoPEi)
- I am Tim Corey (bit.ly/3UD0zAI)
- FreecodeCamp (bit.ly/3GMDVQC)
- NDC Conferences (bit.ly/419dPQc)
- Programming with Mosh (bit.ly/3KEuLqL)

𝐌𝐢𝐜𝐫𝐨𝐬𝐨𝐟𝐭 𝐕𝐢𝐝𝐞𝐨 𝐓𝐮𝐭𝐨𝐫𝐢𝐚𝐥𝐬
- C# (bit.ly/41l0qEg)
- Desktop (bit.ly/3o82scH)
- ASP .NET (bit.ly/413blCU)
Read 10 tweets
Jun 18, 2023
Why should we use NodaTime over Default .NET DateTime ?

These are the 7 reasons

1) Lack of clarity in DateTime especially when comparing local and UTC times🔽👇

#dotnet Image
2) DateTimeKind property and various operations like ToUniversalTime() and ToLocalTime() can lead to unexpected results

3) DateTime does not provide a comprehensive solution for handling time zones.

#dotnet
4) TimeZoneInfo, used in .NET, relies on Windows time zone IDs, which may differ from widely used Olson (tz) identifiers

5) Unfortunately humanity did’ not agree on single calendar (Gregorian, Julian, Coptic and Buddhist) , NodaTime covers this space which default lacks

#dotnet
Read 5 tweets
Jun 14, 2023
Are you using required keyword with properties ?

Since C# 11 we can add required keyword with properties , it will force to initialize that property at the time of object creation.

There are few benefits of using it
- Less chance of error
- Get rid of validation code

#dotnet Image
- If something is essential make it required

Compiler will give error if you don't initialize that property.

📌 P.S:- If you enjoy reading my posts join my weekly .NET Newsletter. Join with 3400+ :

#dotnetlnkd.in/dNHxJGRG
📌Read these 15 awesome topics of .NET via my Newsletter.

Join 3400+ : for upcoming issues.

EP 14: 7 Awesome Features of C# (10)
EP 13: Bogus - A Fake Data Generation
EP 12: Global Exception Handling
EP 11: Default vs Autofac DI Container
EP 10: Action… https://t.co/62ug4BOMVBlnkd.in/dNHxJGRG
twitter.com/i/web/status/1…
Read 4 tweets
Apr 29, 2023
💡𝐃𝐨𝐧’𝐭 𝐑𝐞𝐩𝐞𝐚𝐭 𝐘𝐨𝐮𝐫𝐬𝐞𝐥𝐟 (𝐃𝐑𝐘) 𝐏𝐫𝐢𝐧𝐜𝐢𝐩𝐥𝐞

It states that don’t repeat yourself what it means it is saying don’t duplicate code , avoid duplication. Purpose is to reduce the redundant code in your application 🧵⏬
#dotnet Image
Following the DRY Principle can give us following benefits

1.  Improved maintainability of code

2.  Reduces the risks of bugs

3.  Code becomes easier to understand

#dotnet
If you are not applying DRY Principle you need to test/debug all process separately for similar code.

We can fulfil DRY Principle using Inheritance and Polymorphism.

#dotnet
Read 5 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(