c# - How to make class property readonly? -
c# - How to make class property readonly? -
this question has reply here:
is possible forcefulness auto-property utilize readonly backing field? 6 answerslets see next example:
public data() { connectionstring = defaultconnectionstring; } public data(string connectionstring) { connectionstring = connectionstring; } public string defaultconnectionstring { { homecoming system.configuration.configurationmanager.connectionstrings["defaultconnectionstring"].connectionstring; } } public string connectionstring { get; set; } here having class handle sql connection , operations on basis of connection string or default connection string. , connectionstring property logically using readonly i.e. set constructor. in case property can set else also. there elegant way define such property?
make setter private
public string connectionstring { get; private set; } that way property can set privately , read publicly
c# properties readonly
Comments
Post a Comment