I have something similar to the following very simple code, but I'm getting caught out by the way objects are referenced. I'd like to understand what's going on a little more.
I'm surprised to find that _connection.Name and _connection.Enabled can be modified outside of the class.
internal class ConnectionProperties
{
internal string Name = "Default Name";
internal bool Enabled = true;
}
internal class Data
{
private readonly ConnectionProperties _connection;
internal string ConnectioName => _connection.Name;
internal ConnectionProperties Connection()
{
return _connection;
}
internal Data()
{
this._connection = new ConnectionProperties();
}
}
class Program
{
static void Main(string[] args)
{
Data data = new Data();
Console.WriteLine(data.ConnectioName);
ConnectionProperties temp = data.Connection();
temp.Name = "New Name";
Console.WriteLine(data.ConnectioName);
}
}
OUTPUT:
Default
Name New Name