Skip to content

Instantly share code, notes, and snippets.

@vdonchev
Created November 23, 2015 22:25
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 vdonchev/390c2f0c10aa4f14a1c9 to your computer and use it in GitHub Desktop.
Save vdonchev/390c2f0c10aa4f14a1c9 to your computer and use it in GitHub Desktop.
namespace ReadonlyTest
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public static class Program
{
public static void Main(string[] args)
{
var room = new Room();
room.AddPersons("pesho", "gosho", "misho");
Console.WriteLine(room);
room.Persons.Add("ghost");
Console.WriteLine(room);
}
}
public class Room
{
private readonly List<string> persons = new List<string>();
public List<string> Persons
{
get
{
return this.persons.Select(i => (string)i.Clone()).ToList();
}
}
public void AddPersons(params string[] pers)
{
foreach (var per in pers)
{
this.persons.Add(per);
}
}
public override string ToString()
{
var res = new StringBuilder();
foreach (var person in this.persons)
{
res.AppendLine(person);
}
return res.ToString().Trim();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment