Created
November 23, 2015 22:25
-
-
Save vdonchev/390c2f0c10aa4f14a1c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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