0

So I already got used to using the "usual way of instantiating as a beginner" which is

Employee emp = new Employee();

And then I saw this:

new Employee {
//Some code here...
}

The employee class has this:

public class Employee{
    public string Name
    public Employee{ 
        Name = "Bob";
    }
}

So what is the difference between the two?

  • Do you want a reference to the object or not? – Enigmativity Oct 26 '20 at 05:41
  • Here is a good read for you that expains it https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/how-to-initialize-objects-by-using-an-object-initializer – Jerry Oct 26 '20 at 05:42
  • 2
    The posted `Employee` Class does not look like a valid class. – JohnG Oct 26 '20 at 05:43
  • @Enigmativity Uhm, I dont really have any project going on with this question. I just saw this on a tutorial and I dunno about why did he put it in like that – Aaron Ancheta Oct 28 '20 at 04:35
  • @AaronAncheta - Try to verify the code and the issue you have with it before posting. Can you please do so now? – Enigmativity Oct 28 '20 at 05:04

0 Answers0