您的位置:首页 > 编程语言 > C#

performance optimization in C#

2008-12-10 22:24 561 查看
1. Used always sealed classes when the class haven't any derived classes.
Some additional infos from this point:

The sealed modifier is primarily used to prevent unintended derivation,
but it also enables certain run-time optimizations. In particular, because a sealed class is
known to never have any derived classes, it is possible to transform virtual function member
invocations on sealed class instances into non-virtual invocations.

sealed类可以提高性能

2. Do not loop in a foreach loop over DataRows use the Select() method of the DataTable.

this code costs tooooo much:

foreach(DataRow currentDataRow in currentDataTable.Rows)
{
newDataTable.ImportRow(currentDataRow);
}

this code runs over 300 % faster (depends on rows count):

DataRow[] allRows = currentDataTable.Select();

foreach (DataRow currentDataRow in allRows)
{
newDataTable.ImportRow(currentDataRow);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: