最近使用使用VS2008,发现相比VS2005代码可以少写不少.
看一眼就会用的就不说了.
例1:泛型代理Action,Func
如窗体的BeginInvoke,代理想用就用,再也不需要独立声明了.
///
<summary>
/// 更新节点
/// </summary>
/// <param name="mes"></param>
private void UpdataTreeNodeInvoke( string parent, string nodeText, int index)
{
if (InvokeRequired)
{
this.BeginInvoke( new Action< string, string, int>(UpdataTreeNode), parent, nodeText, index);
}
else
{
UpdataTreeNode(parent, nodeText, index);
}
}
/// 更新节点
/// </summary>
/// <param name="mes"></param>
private void UpdataTreeNodeInvoke( string parent, string nodeText, int index)
{
if (InvokeRequired)
{
this.BeginInvoke( new Action< string, string, int>(UpdataTreeNode), parent, nodeText, index);
}
else
{
UpdataTreeNode(parent, nodeText, index);
}
}
例2: Lambda表达式
C++2011也引入了,值得期待的地方.
VS2005函数:
private
int FileIsOpened(List<
string> openedFiles,
string fileName)
{
string lowerFileName = fileName.ToLower();
for ( int i = 0; i < openedFiles.Count; i++)
{
if (openedFiles[i].ToLower() == lowerFileName)
{
return i;
}
}
return - 1;
}
{
string lowerFileName = fileName.ToLower();
for ( int i = 0; i < openedFiles.Count; i++)
{
if (openedFiles[i].ToLower() == lowerFileName)
{
return i;
}
}
return - 1;
}
更改后VS2008函数,精简了不少
private
int FileIsOpened(List<
string> openedFiles,
string fileName)
{
return openedFiles.FindIndex(p => p.Equals(fileName, StringComparison.OrdinalIgnoreCase));
}
{
return openedFiles.FindIndex(p => p.Equals(fileName, StringComparison.OrdinalIgnoreCase));
}