Thursday, March 8, 2018

Tutorial 14 What are GET SET properties and why we want to use it?

Why we need GET SET properties?

Firstly in Dotnet we need to work with variable and many a times we want to use same variable at 

multiple places and now think of a big project where 25 special developers are working together anybody 

can use it and assign different values to same variable and can violate the project rules so we need to 

implement some rules for each variable.

Lets see with one example :

This is done only for one 

Let's see the inbuilt GET & SET properties in Dotnet :

This properties are provided from dotnet 3.0 to implement and reuse code. This logic introduces us to a defination of Encapsulation.


Can we implement GET SET property automatically?

Yes this can be done easily and we need not to define 2 fields one private and one public to validate field.

We can directly use 

public datatype variablename{get; set;}

this will automatically create one private field at backend in dotnet.

I hope this property blog is clear to you for more clarification kindly comment and we can discuss and understand.








No comments:

Post a Comment