大家好,
我有Question一个有财产的班级Text
public class Question
{
public string Text { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
现在我想通过赋予属性值来创建这种类型的对象.
我可以通过以下两种方式做到这一点:
Question q = new Question { Text = "Some question" };
和
Question q = new Question() { Text = "Some question" };
这两种情况有什么区别,如果它们是相同的,为什么我们需要两者?
谢谢.