王文的博客
频道地址:http://wangwen422.blog.sohu.com/rss
离线订阅:
订阅数量:2  网站名称:其它  Tag(0)  评论(0)  与好友共享    举报
TAG分类:
相关标签:
    最近更新:2008-03-04 01:36:40
提示:当前RSS频道由用户提交推荐而列出,如有不妥,请联系我们及时删除!
在开发中,经常会遇到这种情况,在A.dll中需要反射B.dll中的类型,如果稍不注意,就会产生运行时错误。关于跨程序集的反射,记住两点就可以:(1)如果使用typeof,编译能通过,则跨程序集的反射一定可以正常运行。可以说,typeof是支持强类型的。比如 Type supType = typeof(EnterpriseServerBase.DataAccess.IDBAccesser) ; 如果当前程序集没有添加对EnterpriseServerBase.dll的引用,则编译会报错。(2)如果使用Type.GetType,情况就复杂些,这是因为Type.GetType是非强类型的。Type.GetType的参数是一个string,当string表示的目标类型不在当前程序集中,则运行时Type.GetType会返回null。解决的办法是:首先加载目标程序集,然后再使用Assembly.GetType方法。如 Assembly asmb = Assembly.LoadFrom("EnterpriseServerBase.dll") ; Type supType = asmb.GetType("EnterpriseServerBase.DataAccess.IDBAccesser") ; 注意,当使用Type.GetType的时候,即使你添加了对EnterpriseServerBase.dll的引用,Type.GetType("EnterpriseServerBase.DataAccess.IDBAccesser")也会返回null,这是因为Type.GetType只会在当前程序集中进行类型搜索!
2008-03-01 13:53:13   评论(0)
最近在学习C# 2.0,在.NET Framework 2.0中新增加了System.Nullable泛型结构,它具有处理值类型数据具和处理null的功能。例如: System.Nullable i = 2;i = null;System.Nullable b = null; 另外C#中还提供了上述表示方法的简写形式: int? i = null;bool? b = null; 此时,i除了可以正常处理int值外还可以被赋值为null;b则可以处理true、false和null值。感觉上好像“值类型可以处理null”似的,实际上,上面的System.Nullable是对int的一种扩展,前者可被称为“可空的int”,后者被称为“非空的int”,它们所指的并非同一事物。因此,当把一个可空类型值赋给一个非空类型时,将引发编译错误,例如: int? ni = null;int i = ni; //这一句将引发编译错误 推荐的方法是赋值前对可空类型的值进行检查,在C#中使用??运算符分配默认值,如: int? ni = null;int i = ni ?? 0; ??运算符会首先判断左操作数是否为空,如果为空则返回??后面给出的默认值,否则返回左操作数,其意义类似于: int? ni = null;int i = ni.HasValue ? ni.Value : 0; 提醒:System.Nullable并不等同于int,值类型还是值类型,int类型不能处理null,System.Nullable是一种新的结构类型,被用来处理int类型数据和null。
2008-02-28 21:46:45   评论(0)
内容摘要:编写一个函数,要求输入年月日时分秒,输出该年月日时分秒的下一秒。如输入2004年12月31日23时59分59秒,则输出2005年1月1日0时0分0秒关键词:华为面试题 C语言面试题 本文地址:http://www.teecool.com/post/2007072910.html内容正文: 找错Void test1(){  char string[10];  char* str1="0123456789";strcpy(string, str1);} Void test2(){  char string[10], str1[10];for(I=0; I
2008-02-24 21:06:03   评论(0)
1 GridView增加自动编号列 2 然后在 GridView 的 RowDataBound 事件中,设定每一列的 lblNo 的 Text 属性值为 RowIndex+1。 因为 RowIndex 起始编号为 0 ,故每列的自动编号为 RowIndex+1。 Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound Dim oLabel As Label If e.Row.RowType = DataControlRowType.DataRow Then oLabel = CType(e.Row.Cells(0).FindControl("lblNo"), Label) oLabel.Text = (e.Row.RowIndex + 1).ToString() End If End Sub Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound Dim oLabel As Label If e.Row.RowType = DataControlRowType.DataRow Then oLabel = CType(e.Row.Cells(0).FindControl("lblNo"), Label) oLabel.Text = (e.Row.RowIndex + 1).ToString() End IfEnd Sub 以上的写法遇到 GridView 分页时,都是由 1 开始编号,若需分页需要接续编号,可改用修改如下。 GridView1.RowDataBound Handles System.Web.UI.WebControls.GridViewRowEventArgs) As e ByVal Object, sender GridView1_RowDataBound(ByVal Sub 1 Protected>2 Dim oLabel As Label Di...[查看详细内容..]
2008-02-20 19:04:58   评论(0)
在gridview中,我们都希望能在删除记录时,能弹出提示框予以提示,在asp.net 1.1中,都可以很容易实现,那么在asp.net 2.0中要如何实现呢?下面举例子说明,首先在HTML页面中设计好如下代码:<asp:GridView DataKeyNames="CategoryID" ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_RowDataBound" OnRowDeleted="GridView1_RowDeleted" OnRowDeleting="GridView1_RowDeleting"><Columns><asp:BoundField DataField="CategoryID" HeaderText="CategoryID" /><asp:BoundField DataField="CategoryName" HeaderText="CategoryName" /><asp:TemplateField HeaderText="Select"><ItemTemplate><asp:LinkButton ID="LinkButton1" CommandArgument='<%# Eval("CategoryID") %>' CommandName="Delete" runat="server">Delete</asp:LinkButton></ItemTemplate></asp:TemplateField></Columns></asp:GridView>  在上面的代码中,我们设置了一个链接linkbutton,其中指定了commandname为"Delete",commandargument为要删除的记录的ID编号,注意一旦commandname设置为delete这个名称后,gridview中...[查看详细内容..]
2008-02-20 01:27:57   评论(0)
在asp.net 2.0下,gridview是十分方便的了,加一个DATASOURCE系列的控件的话,就可以马上和gridview绑定,十分方便。但其实也可以使用datatable或者dataview的,这个时候就不是用datasource系列控件了。下面讲下如何在asp.net 2.0下,实现gridview控件的翻页,各列排序,编辑的功能。 首先,我们读取的是northwind数据库中的employee表。放置一个gridview后,添加几个绑定的列,代码如下 首先,我们要实现分页,把AllowPaging设置为true,并设置每页的分页条数,最后在codebehind中写入protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; BindGrid(); } 为了实现每列都可以自动点击排序,可以设置allowsorting=true,然后设置OnSorting="GridView1_Sorting",其中gridview_sorting代码为 protected void GridView1_Sorting(object sender, GridViewSortEventArgs e) { ViewState["sortexpression"] = e.SortExpression; if (ViewState["sortdirection"] == null) { ViewState["sortdirection"] = "asc"; ...[查看详细内容..]
2008-02-19 23:22:04   评论(0)
提交成功...