【发布时间】:2010-07-30 04:33:21
【问题描述】:
如果我需要这样做:
var connection = new Connection(host);
connection.Execute(Commands.Delete);
这样做有什么问题吗:
(new Connection(host)).Execute(Commands.Delete);
第一个示例可能更具可读性,但如果我需要多次执行此操作,则第二个效果更好:
(new Connection(anotherHost)).Execute(Commands.Create);
(new Connection(someOtherHost)).Execute(Commands.Update);
(new Connection(host)).Execute(Commands.Delete);
【问题讨论】:
-
你甚至可以使用
new Connection(anotherHost).Execute(Commands.Create)(即没有括号),这样看起来更流畅 -
啊酷。甚至没想过要尝试。
标签: c# declaration throwaway