本文介绍了这是什么语法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
this.Add(new TabPage
{
Text = text
});
我在反编译TabControl的源代码后看到了这一点.我可以推断出它在做什么,但我从未见过像以前那样创建过对象.
I saw this after decompiling the source for TabControl. I can sort of infer what it''s doing, but I''ve never seen an object being created like that before.
new TabPage { Text = text };
推荐答案
// Instead of doing:
Person p = new Person();
p.Name = "Naerling";
p.LastName = "Hell yeah!";
p.Age = 24;
// Or...
Person p = new Person() { Name = "Naerling", LastName = "Hell yeah!", Age = 24 };
// And then...
this.AddPersonToPhoneBook(p);
// You could be doing:
this.AddPersonToPhoneBook(new Person() { Name = "Naerling", LastName = "Hell yeah!", Age = 24 });
我个人从不使用这种语法.我没有理由不这样做.
Personally I never use this syntax. I have no good reason not to though.
这篇关于这是什么语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!