Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# protected property or field

Tags:

c#

properties

Do you think it's better to always make protected class members an auto-implemented protected property to keep isolation or make it protected field is enough?

protected bool test { get; set; } 

or

protected bool test; 
like image 491
Vince Avatar asked Jan 27 '10 17:01

Vince


1 Answers

Generally, you should use autoproperties - this allow you to easily add verification, or anything else you need later on. This is especially important if the protected member will be used by classes outside your assembly, as adding such code won't break your contract with them, whereas changing a field to a method or property will.

like image 81
thecoop Avatar answered Oct 08 '22 02:10

thecoop