CallBack 匿名委托实现自定义排序 Readonly vs const
1. 在CallBack之后保持滚动条的位置:
在Asp.Net1.1中,CallBack之后保持滚动条的位置是一件非常痛苦的事情,特别是页中有一个Grid并且想要编辑特定的行。为了不停留在想要得行,页面会重新加载并且必须在顶部向下滚动。在ASP2.0中,只需要简单的在页面的属性中加入MaintainScrollPostionOnPostBack属性即可
<%@ Page Language="C#" MaintainScrollPositionOnPostback="true" AutoEventWireup="true" CodeFile="" Inherits=""%>
2. 匿名委托实现自定义排序
public void SortByCommentCount(List<Article> articleList, bool ascending)
{
articleList.Sort(delegate(Article a, Article b)
{
return (a.CommentCount - b.CommentCount) * (ascending ? 1 : -1);
});
}
{
articleList.Sort(delegate(Article a, Article b)
{
return (a.CommentCount - b.CommentCount) * (ascending ? 1 : -1);
});
}
3. Readonly是运行时常量,Const是编译时常量;前者灵活,后者高效;前者可以用于任何类型,后者只能用于数字和字符串