Lets see following example:
public Data()
{
ConnectionString = DefaultConnectionString;
}
public Data(string connectionString)
{
ConnectionString = connectionString;
}
public string DefaultConnectionString
{
get
{
return System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnectionString"].ConnectionString;
}
}
public string ConnectionString { get; set; }
here I am having class which handle sql connection and operations on basis of connection string or by default connection string. And ConnectionString
property which logically I am using as readonly
i.e. only set from constructor
. But in this case property can set from any where else also.
So there is any elegant way to define such property?