Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Constructor based object initialization
- Employee currentUser = new Employee();
- currentUser.Name = "Bob";
- Employee currentUser = new Employee() { Name = "Bob" };
- internal class Foo
- {
- public string Bar { get; set; }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Foo f = new Foo()
- {
- Bar = "Baaz"
- };
- Console.WriteLine("Now the old way sugar");
- Foo f2 = new Foo();
- f2.Bar = "Baaz";
- }
- }
- IL_0000: nop
- IL_0001: newobj instance void SimpleDataPlayGround.Foo::.ctor()
- IL_0006: stloc.2
- IL_0007: ldloc.2
- IL_0008: ldstr "Baaz"
- IL_000d: callvirt instance void SimpleDataPlayGround.Foo::set_Bar(string)
- IL_0012: nop
- IL_0013: ldloc.2
- IL_0014: stloc.0
- IL_0015: ldstr "Now the old way sugar"
- IL_001a: call void [mscorlib]System.Console::WriteLine(string)
- IL_001f: nop
- IL_0020: newobj instance void SimpleDataPlayGround.Foo::.ctor()
- IL_0025: stloc.1
- IL_0026: ldloc.1
- IL_0027: ldstr "Baaz"
- IL_002c: callvirt instance void SimpleDataPlayGround.Foo::set_Bar(string)
- IL_0031: nop
- IL_0032: ret
- Employee tmp = new Employee();
- tmp.Name = "Bob";
- Employee currentUser = tmp;
- Employee currentUser = new Employee { Name = "Bob" };
- currentUser = new Employee { Name = currentUser.Name + "Foo" };
Add Comment
Please, Sign In to add comment