Consider the following code snippet:
public class Foo
{
public int ID { get; set; }
public string FirstName { get; set; }
...
public Foo(int Id, string firstName)
{
ID = Id;
FirstName = firstName;
}
}
Assuming we have a method which takes in Foo
object as a parameter. I can create the object as follows:
var first = new Foo { ID = 1, FirstName = "Test"};
var second = new Foo(1, "Test");
Then pass to the method which is accepting the object as a parameter. My actual classes consist of 10+ properties, I simplified it for the question.
My question is, is there a difference here or both doing the same thing? or it's more a case of preference.
Thanks in advance for your help.