在与同事讨论了在C#3中使用'var'关键字后,我想知道人们对通过var的类型推断的适当用途有什么看法?
例如,我在可疑情况下懒得使用var,例如: -
foreach(var item in someList) { // ... } // Type of 'item' not clear.
var something = someObject.SomeProperty; // Type of 'something' not clear.
var something = someMethod(); // Type of 'something' not clear.
Run Code Online (Sandbox Code Playgroud)
var的更合理用途如下: -
var l = new List<string>(); // Obvious what l will be.
var s = new SomeClass(); // Obvious what s will be.
Run Code Online (Sandbox Code Playgroud)
有趣的是LINQ似乎有点灰色,例如: -
var results = from r in dataContext.SomeTable
select r; // Not *entirely clear* what results will be …Run Code Online (Sandbox Code Playgroud) 总而言之,我理解对于广泛定制的对话框,我需要创建自己的表单和ShowDialog().但是,在我目前的情况下,我只想扩展MessageBox类,以便CustomMessageBox能够显示由系统确定的不同图标.
我之前没有覆盖过这样的控制,我甚至不知道从哪里开始.有人能指出我正确的方向吗?
谢谢你的时间.