Created
November 23, 2015 22:32
-
-
Save vdonchev/b1151e3124cdfe671bd8 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); | |
} | |
} | |
public class Room | |
{ | |
private readonly List<string> persons = new List<string>(); | |
public IEnumerable<string> Persons | |
{ | |
get | |
{ | |
return this.persons.AsEnumerable(); | |
} | |
} | |
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