代码理解(2009.11.20)

本文作者分享了作为新手在C# Web开发中遇到的问题及理解,包括Page_Load方法、IDictionary使用、序列化属性、as关键字、IList泛型接口、IsClientScriptBlockRegistered方法、FindControl方法和HiddenField控件的应用。

 上班一个多星期了,但是,还是让我“熟悉环境和业务”,很少给我任务。于是,自己看项目代码。有很多不理解和陌生的地方,总结如下:

1.为什么不是Page_Load(),ProcessPage_Load()是什么意思?

protected   override   void  ProcessPage_Load( object  sender, EventArgs e)
{
   
// code
}

好像是自定义事件。

            PrePage_Load(sender, e);
            ProcessPage_Load(sender, e);
            AfterPage_Load(sender, e);

2.IDictionary的用法有点奇怪,IDictionary是个接口,接口的用法不是加“:”来继承吗?接口类型的数据?

ContractedBlock.gif ExpandedBlockStart.gif 函数字典
        /// <summary>
        
/// Function Dictionary
        
/// </summary>
        public IDictionary FunctionDictionary
        {
            
get
            {
                
return _FunctionDictionary;
            }
            
set
            {
                _FunctionDictionary 
= value;
            }
        }

 3. [Serializable]

在一个类的声明的前面,加[Serializable]表示这个类可以被序列化。如果一个类能被序列化,那么他的所有成员变量都应该是可以被序列化的。至于什么是序列化,暂且不管。

[Serializable]
class  A
{
}

4. as用于在兼容的引用类型之间执行转换。

例如:

string s = someObject as string;
if (s != null)
{
    // someObject is a string.
}

as 运算符类似于强制转换操作;但是,如果转换不可行,as 会返回 null 而不是引发异常。更严格地说,这种形式的表达式

expression as type    等效于    expression is type ? (type)expression : (type)null

只是 expression 只被计算一次。

         ///   <summary>
        
///  CSA用户表 Interface
        
///   </summary>
         public   static  ICsaUserBiz iCsaUserBiz  =  ContainerAccessorUtil.GetContainer()[ " CCLOG.CsaUserBiz " as  ICsaUserBiz;

5. IList<>的意思?IList是列表,IList<AAA>表示这个列表里面放AAA类型的实例。

IList是接口,IList<>是泛型。

IList可以理解为顶层接口 ,比如 list,ArrayList都是继承他的。

IList ilist = new list();
Ilist <> 里面是泛型,说明你里面装的什么 。可以装实例,也可以装基本类型。
Ilist <string> ilist= new list <string>();

ContractedBlock.gif ExpandedBlockStart.gif Code
        /// <summary>
        
/// 根据QueryString查询
         
/// </summary>
        
/// <param name="QueryString">查询字符串</param>
        
/// <returns>记录列表</returns>
        IList<CsaUserModel> SelectAllByQueryString(String filter);

6. IsClientScriptBlockRegistered

ContractedBlock.gif ExpandedBlockStart.gif Code
             string js = sb.ToString();
            
if (!IsClientScriptBlockRegistered("PageJs_PreRender"))//注册JS
            {
                RegisterClientScriptBlock(
"PageJs_PreRender", js);
            }

链接:http://zhidao.baidu.com/question/52092132.html?si=1

7. FindControl

ContractedBlock.gif ExpandedBlockStart.gif Code
           protected void AttachmentGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            
if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add(
"onMouseOver""this.className='list_light';");
                
if (e.Row.RowIndex % 2 == 1)
                {
                    e.Row.Attributes.Add(
"onMouseOut""this.className='list_double';");
                }
                
else
                {
                    e.Row.Attributes.Add(
"onMouseOut""this.className='list_single';");
                }
                AttachmentModel attachmentModel 
= (AttachmentModel)e.Row.DataItem;
                ((Label)e.Row.FindControl(
"lblName")).Text = attachmentModel.FileName;
                ((Label)e.Row.FindControl(
"lblType")).Text = attachmentModel.Type;
                ((Label)e.Row.FindControl(
"lblRemark")).Text = attachmentModel.Remark;
                ((Label)e.Row.FindControl(
"lblCreateUser")).Text = attachmentModel.CreateUser;
                ((Label)e.Row.FindControl(
"lblCreateDateTime")).Text = attachmentModel.CreateDateTime.ToString();
                ((LinkButton)e.Row.FindControl(
"lbtnDownLoad")).CommandArgument = attachmentModel.Id;
            }
        }

 8. HiddenField

                  if  (Session[ " MenuId " !=   null )
                {
                    txtHiddenMenuId.Value 
=  Session[ " MenuId " ].ToString();
                }

http://zhidao.baidu.com/question/69402024.html

转载于:https://www.cnblogs.com/niuniu1985/archive/2009/11/23/1606782.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值