Skip to content

Instantly share code, notes, and snippets.

@lgolubyev
Created May 23, 2022 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lgolubyev/ee235ff6ff435892516f574f9deed665 to your computer and use it in GitHub Desktop.
Save lgolubyev/ee235ff6ff435892516f574f9deed665 to your computer and use it in GitHub Desktop.
class Program
{
static void Main(string[] args)
{
MyClass myClass = new MyClass();
((List<string>)myClass.ReadOnlyNameCollection).Add("######From Client#####");
myClass.Print();
}
}
class MyClass
{
List<string> _nameCollection = new List<string>();
public MyClass()
{
_nameCollection.Add("Rob");
_nameCollection.Add("John");
_nameCollection.Add("Jummy");
_nameCollection.Add("Derek");
}
public IEnumerable<string> ReadOnlyNameCollection
{
get { return _nameCollection.AsEnumerable(); }
}
public void Print()
{
foreach (var item in ReadOnlyNameCollection)
{
Console.WriteLine(item);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment