2 ways to create new object by setting property values
- by Samvel Siradeghyan
Hi all
I have a class Question which has a property Text
public class Question
{
public string Text { get; set; }
}
Now I wont create on object of this type by giving value to property.
I can do that in this two ways:
Question q = new Question { Text = "Some question" };
and
Question q = new Question() { Text = "Some question" };
Is there any difference between this two cases and if they are the same, why we need both?
Thanks.