-
-
Save asbjornu/64868b3db611f127faa61cd21f486654 to your computer and use it in GitHub Desktop.
Object initializer surprise.
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
void Main() | |
{ | |
var t = new Thing(new Thang { Thung = "lol" }) | |
{ | |
Thang = { { "OMG" } } | |
}; | |
t.Dump(); | |
} | |
class Thing | |
{ | |
private readonly Thang _thang; | |
public Thing(Thang thang) | |
{ | |
_thang = thang; | |
} | |
public Thang Thang | |
{ | |
get { return _thang; } | |
} | |
} | |
class Thang : IEnumerable | |
{ | |
public string Thung { get; set; } | |
public void Add(string s) | |
{ | |
Thung = s; | |
} | |
IEnumerator IEnumerable.GetEnumerator() | |
{ | |
return new[] { Thung }.GetEnumerator(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment