Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Collections.Immutable;
- using System.Text;
- class Program
- {
- static void Main()
- {
- var foo = new Foo();
- Console.WriteLine(foo);
- (foo.Something as IDictionary<string, string>).Add("6", "six");
- Console.WriteLine(foo);
- }
- }
- class Foo
- {
- private readonly Dictionary<string, string> something;
- public Foo()
- {
- this.something = new Dictionary<string, string>();
- this.something.Add("1", "one");
- this.something.Add("2", "two");
- this.something.Add("3", "three");
- this.something.Add("4", "four");
- this.something.Add("5", "five");
- }
- public IReadOnlyDictionary<string, string> Something
- {
- get
- {
- return this.something;
- //return this.something.ToImmutableDictionary();
- }
- }
- public override string ToString()
- {
- var sb = new StringBuilder();
- foreach (var item in this.something)
- {
- sb.AppendLine($"{item.Key}: {item.Value}");
- }
- return sb.ToString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement