2 ways to create new object by setting property values

Posted by Samvel Siradeghyan on Stack Overflow See other posts from Stack Overflow or by Samvel Siradeghyan
Published on 2010-12-22T10:48:31Z Indexed on 2010/12/22 10:54 UTC
Read the original article Hit count: 411

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET