<li id="o9kx0"><meter id="o9kx0"></meter></li>
<span id="o9kx0"></span>
<span id="o9kx0"></span>\r\n\r\n\r\n\r\n \r\n \r\n  \r\n   \r\n    \r\n    <\/td>\r\n    \r\n    【登陸】【注冊(cè)】\r\n    <\/td>\r\n    <\/tr>\r\n    <\/tbody>\r\n   <\/table>\r\n  <\/td>\r\n <\/tr>\r\n \r\n  <\/div>\r\n\r\n首頁   |<\/a><\/div>\r\n  \r\n\r\n新聞中心 |<\/a><\/div>\r\n  \r\n\r\n通服產(chǎn)品 |<\/a><\/div>\r\n  \r\n\r\n公司業(yè)績 |<\/a><\/div>\r\n  \r\n\r\n服務(wù)中心 |<\/a><\/div>\r\n  \r\n\r\n解決方案 |<\/a><\/div>\r\n  \r\n\r\n關(guān)于我們 |<\/a><\/div>\r\n<\/td>\r\n <\/tr>\r\n \r\n  \r\n   \r\n \r\n  
  • <\/li>\r\n <\/ul>\r\n<\/div>\r\n  <\/td>\r\n <\/tr>\r\n<\/tbody>\r\n<\/table>\r\n\r\n\r\n \r\n \r\n \r\n  \r\n  \r\n  \r\n  首頁 > 通服產(chǎn)品<\/td>\r\n   <\/td> <\/td>\r\n  返回首頁<\/a><\/td>\r\n  <\/tr>\r\n  <\/table>\r\n  <\/div>\r\n <\/td>\r\n <\/tr>\r\n <\/tbody>\r\n<\/table>\r\n\r\n \r\n \r\n  \r\n  
    \r\n    \r\n  <\/div>\r\n   \r\n    \r\n    基建產(chǎn)品<\/p>\r\n    \r\n    普通基建<\/a>美化基建<\/a>\r\n    <\/div>\r\n    無源器件<\/p>\r\n    \r\n     天線<\/a> 負(fù)載<\/a>\r\n     功分器<\/a> 合路器<\/a>\r\n     耦合器<\/a> 雙工器<\/a>\r\n     AC安裝配件<\/a> 屏蔽器<\/a>\r\n    <\/div>\r\n    防雷產(chǎn)品<\/p>\r\n    \r\n     避雷器<\/a> 防雷箱<\/a>\r\n    <\/div>\r\n    電源產(chǎn)品<\/p>\r\n    \r\n     開關(guān)電源<\/a> USP電源<\/a>\r\n     遠(yuǎn)供電源<\/a> 電源配套<\/a>\r\n    <\/div>\r\n    IP通訊類產(chǎn)品<\/p>\r\n    \r\n     IP網(wǎng)絡(luò)產(chǎn)品<\/a> IP無線產(chǎn)品<\/a>\r\n     IP安全產(chǎn)品<\/a> IP存儲(chǔ)及服務(wù)器<\/a>\r\n     IP多媒體產(chǎn)品<\/a> IP管理產(chǎn)品<\/a>\r\n     H3C產(chǎn)品<\/a> 邁普產(chǎn)品<\/a>\r\n     迪普產(chǎn)品<\/a>\r\n    <\/div>\r\n    工程輔材<\/p>\r\n    \r\n     射頻組件<\/a> 電纜組件<\/a>\r\n     光纖組件<\/a> 五類纜組件<\/a>\r\n     接地線<\/a> 輔材包<\/a>\r\n     套管<\/a> 緊固件<\/a>\r\n    <\/div>\r\n    連接器<\/p>\r\n    \r\n     射頻連接器<\/a> 光纖連接器<\/a>\r\n     轉(zhuǎn)換頭<\/a>\r\n    <\/div>\r\n    服務(wù)類<\/p>\r\n    \r\n     工程建設(shè)類<\/a> 工程維護(hù)類<\/a>\r\n     軟件類<\/a>\r\n    <\/div>\r\n    品牌分銷<\/p>\r\n    \r\n     華為產(chǎn)品<\/a>\r\n    <\/div>\r\n    配件類<\/p>\r\n    \r\n     配件類<\/a> 標(biāo)準(zhǔn)件<\/a>\r\n    <\/div>\r\n    其他<\/p>\r\n    \r\n     郵費(fèi)差額<\/a> 工程類服務(wù)費(fèi)用<\/a>\r\n     折扣<\/a> 設(shè)備<\/a>\r\n    <\/div>\r\n   <\/div>\r\n  <\/td>\r\n  \r\n  \r\n  產(chǎn)品類別:\r\n     <\/asp:DropDownList>\r\n     \r\n  關(guān)鍵字:<\/asp:TextBox>\r\n     \r\n     \r\n  <\/div>\r\n  
     <\/div>\r\n  
    \r\n    \r\n    \r\n     \r\n     \r\n     \r\n     \r\n       \r\n     <\/td>\r\n      <\/td>\r\n     產(chǎn)品型號(hào):<\/td>\r\n     <%#Eval(\"pr_guige\")%><\/span>查看詳情<\/a><\/span><\/td>\r\n     <\/tr>\r\n     \r\n      <\/td>\r\n     產(chǎn)品編碼:<\/td>\r\n     <%#Eval(\"pr_bianma\")%><\/td>\r\n     <\/tr>\r\n     \r\n      <\/td>\r\n     產(chǎn)品描述:<\/td>\r\n     <%#Eval(\"pr_ms\")%><\/td>\r\n     <\/tr>\r\n      <\/td><\/tr>\r\n     <\/table>\r\n     <\/div>\r\n    <\/ItemTemplate>\r\n    <\/asp:Repeater>\r\n    \r\n    \r\n      <\/webdiyer:AspNetPager>\r\n  <\/div>\r\n  <\/div>\r\n    \r\n  <\/td>\r\n <\/tr>\r\n<\/tbody>\r\n<\/table>\r\n\r\n\r\n \r\n \r\n \r\n \r\n <\/td>\r\n <\/tr>\r\n <\/tbody>\r\n<\/table>\r\n<\/form>\r\n<\/body>\r\n<\/html><\/pre>

    Backend code <\/p>

    Tb_productsHelper helper = new Tb_productsHelper();\r\n    IList list = helper.GetAllListBySql(product_sql);\r\n    this.AspNetPager1.RecordCount = list.Count;\/\/綁定總數(shù)量\r\n    this.AspNetPager1.AlwaysShow = true;\r\n    \/\/先聲明一個(gè)分頁類對(duì)象\r\n    PagedDataSource ps = new PagedDataSource();\r\n    ps.AllowPaging = true;\r\n    ps.PageSize = this.AspNetPager1.PageSize;\r\n    ps.CurrentPageIndex = this.AspNetPager1.CurrentPageIndex-1;\r\n    ps.DataSource = list;\r\n    this.rp.DataSource = ps;\r\n    this.rp.DataBind();<\/pre>

    For more .NET implementation of Repeater control + AspNetPager control paging related articles, please pay attention to the PHP Chinese website! <\/p>"}

    国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

    Home Backend Development C#.Net Tutorial .NET implements Repeater control + AspNetPager control paging

    .NET implements Repeater control + AspNetPager control paging

    Feb 08, 2017 am 09:20 AM

    Of course first you have to put the bin file into your project and add it to your toolbar

    //頁頭需引用的
    <%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
     
    控件部分(格式已經(jīng)設(shè)計(jì)好)
    <webdiyer:AspNetPager ID="AspNetPager1" runat="server" AlwaysShow="True" FirstPageText="<font face=&#39;Webdings&#39;>9</font>"
     LastPageText="<font face=&#39;Webdings&#39;>:</font>" NextPageText="<font face=&#39;Webdings&#39;>8</font>"
     PrevPageText="<font face=&#39;Webdings&#39;>7</font>" ShowCustomInfoSection="Left" InputBoxStyle="width:19px"
     TextAfterInputBox="頁" TextBeforeInputBox="轉(zhuǎn)到第" CustomInfoHTML="共檢索到<strong>%RecordCount%</strong>條記錄 頁次:<strong>%CurrentPageIndex%/%PageCount%</strong> 每頁<strong>%PageSize%</strong>條"
     HorizontalAlign="Right" Width="100%" ShowInputBox="Always" OnPageChanged="AspNetPager1_PageChanged"
     PageSize="20" ShowBoxThreshold="1">
    </webdiyer:AspNetPager>

    Background binding code

    void databind()
        {
          int QYId = Convert.ToInt32(Request.Cookies["CompenyUser"].Value);//企業(yè)的Id
          DataTable dt = bll.Viewlist(QYId);
          this.AspNetPager1.RecordCount = dt.Rows.Count;//獲取數(shù)據(jù)的總數(shù)
     
          PagedDataSource pds = new PagedDataSource();
          pds.DataSource = dt.DefaultView;//為控件綁定數(shù)據(jù)
          pds.AllowPaging = true;//分頁啟用
          pds.PageSize = AspNetPager1.PageSize;//獲取每頁顯示的數(shù)量
          pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
     
          Repeater1.DataSource = pds;
          Repeater1.DataBind();
        }

    Paging, just put the binding in the AspNetPager1_PageChanged event

    Let me give you another example

    Foreground page code

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="TF_Product.aspx.cs" Inherits="TF_Product" %>
      
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      
      
    <%@ Register assembly="AspNetPager" namespace="Wuqi.Webdiyer" tagprefix="webdiyer" %>
      
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
      <title>通服產(chǎn)品</title>
      <script src="jquery.js" type="text/javascript"></script>
      <script type="text/javascript">
      $(document).ready(function()
      {
        //slides the element with class "menu_body" when paragraph with class "menu_head" is clicked
        $("#firstpane p.menu_head").click(function()
        {
          $(this).css({backgroundImage:"url(down.png)"}).next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("slow");
          $(this).siblings().css({backgroundImage:"url(left.png)"});
        });
      });
      </script>
    <style type="text/css">
    .menu_list { width: 229px; font-size:13px; }
    .menu_head { padding: 8px 60px; cursor: pointer; position: relative; margin:1px; height:16px; background: #DFEDFA url(left.png) center right no-repeat; }
    .menu_body { display:none;}
    .menu_body a { display:block; color:#006699; background-color:#EFEFEF; padding-left:60px; padding-top:8px; padding-bottom:3px; text-decoration:none; }
    .menu_body a:hover { color: #000000; text-decoration:underline; }
    </style>
    <meta name="keywords" content="通服科技">
    <meta name="description" content="江西通服科技有限公司">
    <link href="./Index_files/style.css" type="text/css" rel="stylesheet">
    <script src="js/AC_RunActiveContent.js" type="text/javascript"></script>
    <!--焦點(diǎn)圖-->
    <style type="text/css">
    .anpager{background:#DFEDFA none repeat scroll 0 0;border:1px solid #CCCCCC;color:#FFFFFF;padding:4px 5px 4px 5px;}
    .container, .container *{margin:0; padding:0;}
      
    .container{width:886px; height:267px; overflow:hidden;position:relative;}
      
    .slider{position:absolute;}
    .slider li{ list-style:none;display:inline;}
    .slider img{ width:886px; height:267px; display:block;}
      
    .num{ position:absolute; right:5px; bottom:5px;}
    .num li{
      float: left;
      color: #FF7300;
      text-align: center;
      line-height: 16px;
      width: 16px;
      height: 16px;
      font-family: Arial;
      font-size: 12px;
      cursor: pointer;
      overflow: hidden;
      margin: 3px 1px;
      border: 1px solid #FF7300;
      background-color: #fff;
    }
    .num li.on{
      color: #fff;
      line-height: 21px;
      width: 21px;
      height: 21px;
      font-size: 16px;
      margin: 0 1px;
      border: 0;
      background-color: #FF7300;
      font-weight: bold;
    }
    </style>
    <!--焦點(diǎn)圖-->
    </head>
    <body>
    <form runat="server">
    <!--頭部-->
    <table width="878" height="114" border="0" align="center" cellpadding="0" cellspacing="2" bgcolor="#FFFFFF">
     <tbody>
     <tr>
      <td height="77">
       <table width="878px" border="0" cellpadding="0" cellspacing="0">
        <tbody>
        <tr><td width="73%" height="53" rowspan="2" align="left"><img src="./Index_files/LOGO_SY180-60.png" width="178" height="60" border="0"></td>
        <td width="27%" align="right" valign="top">
        【登陸】【注冊(cè)】
        </td>
        </tr>
        </tbody>
       </table>
      </td>
     </tr>
     <tr>
      <td width="878" align="center" style=" border-bottom:1px solid blue;" ><div style="width:100px; float:left;"></div>
    <div id="nav" align="center">
    <a href="Default.aspx" target="_self" style="color:Black;">首頁   |</a></div>
      
    <div id="nav" align="center">
    <a href="TF_RecList.aspx" target="_self" style="color:Black;">新聞中心 |</a></div>
      
    <div id="nav" align="center">
    <a href="TF_Product.aspx" target="_self" style="color:Black;">通服產(chǎn)品 |</a></div>
      
    <div id="nav" align="center">
    <a href="TF_Objects.aspx" target="_self" style="color:Black;">公司業(yè)績 |</a></div>
      
    <div id="nav" align="center">
    <a href="TF_Servers.aspx" target="_self" style="color:Black;">服務(wù)中心 |</a></div>
      
    <div id="nav" align="center">
    <a href="TF_Solution.aspx" target="_self" style="color:Black;">解決方案 |</a></div>
      
    <div id="nav" align="center">
    <a href="AboutUs.aspx" target="_self" style="color:Black;">關(guān)于我們 |</a></div>
    </td>
     </tr>
     <tr>
      <td align="center" width="878px">
       <div class="container" id="idTransformView">
     <ul class="slider" id="idSlider">
      <li><img src="images/01.jpg"/></li>
     </ul>
    </div>
      </td>
     </tr>
    </tbody>
    </table>
    <!--中間-->
    <table width="890" border="0" align="center" cellpadding="0" cellspacing="2" bgcolor="#FFFFFF">
     <tbody>
     <tr>
     <td>
      <div style="border:1px solid #DFEDFA; height:26px; padding-top:5px; padding-left:1%">
      <table width="100%">
      <tr>
      <td>首頁 > 通服產(chǎn)品</td>
      <td> </td><td> </td>
      <td align="right"><a href="Default.aspx">返回首頁</a></td>
      </tr>
      </table>
      </div>
     </td>
     </tr>
     </tbody>
    </table>
    <table width="890" border="0" align="center" cellpadding="0" cellspacing="2" bgcolor="#FFFFFF">
     <tbody>
     <tr>
      <td width="229" valign="top">
      <div>
        <img src="img/20140305165205.jpg" width="229px" />
      </div>
       <div id="firstpane" class="menu_list">
        <!--Code for menu starts here-->
        <p class="menu_head">基建產(chǎn)品</p>
        <div class="menu_body">
        <a href="TF_Product.aspx?id=45">普通基建</a><a href="TF_Product.aspx?id=46">美化基建</a>
        </div>
        <p class="menu_head">無源器件</p>
        <div class="menu_body">
         <a href="TF_Product.aspx?id=5">天線</a> <a href="TF_Product.aspx?id=14">負(fù)載</a>
         <a href="TF_Product.aspx?id=11">功分器</a> <a href="TF_Product.aspx?id=17">合路器</a>
         <a href="TF_Product.aspx?id=47">耦合器</a> <a href="TF_Product.aspx?id=56">雙工器</a>
         <a href="TF_Product.aspx?id=70">AC安裝配件</a> <a href="TF_Product.aspx?id=89">屏蔽器</a>
        </div>
        <p class="menu_head">防雷產(chǎn)品</p>
        <div class="menu_body">
         <a href="TF_Product.aspx?id=10">避雷器</a> <a href="TF_Product.aspx?id=57">防雷箱</a>
        </div>
        <p class="menu_head">電源產(chǎn)品</p>
        <div class="menu_body">
         <a href="TF_Product.aspx?id=12">開關(guān)電源</a> <a href="TF_Product.aspx?id=23">USP電源</a>
         <a href="TF_Product.aspx?id=61">遠(yuǎn)供電源</a> <a href="TF_Product.aspx?id=81">電源配套</a>
        </div>
        <p class="menu_head">IP通訊類產(chǎn)品</p>
        <div class="menu_body">
         <a href="TF_Product.aspx?id=27">IP網(wǎng)絡(luò)產(chǎn)品</a> <a href="TF_Product.aspx?id=29">IP無線產(chǎn)品</a>
         <a href="TF_Product.aspx?id=30">IP安全產(chǎn)品</a> <a href="TF_Product.aspx?id=31">IP存儲(chǔ)及服務(wù)器</a>
         <a href="TF_Product.aspx?id=32">IP多媒體產(chǎn)品</a> <a href="TF_Product.aspx?id=33">IP管理產(chǎn)品</a>
         <a href="TF_Product.aspx?id=71">H3C產(chǎn)品</a> <a href="TF_Product.aspx?id=72">邁普產(chǎn)品</a>
         <a href="TF_Product.aspx?id=73">迪普產(chǎn)品</a>
        </div>
        <p class="menu_head">工程輔材</p>
        <div class="menu_body">
         <a href="TF_Product.aspx?id=6">射頻組件</a> <a href="TF_Product.aspx?id=7">電纜組件</a>
         <a href="TF_Product.aspx?id=8">光纖組件</a> <a href="TF_Product.aspx?id=9">五類纜組件</a>
         <a href="TF_Product.aspx?id=18">接地線</a> <a href="TF_Product.aspx?id=62">輔材包</a>
         <a href="TF_Product.aspx?id=82">套管</a> <a href="TF_Product.aspx?id=83">緊固件</a>
        </div>
        <p class="menu_head">連接器</p>
        <div class="menu_body">
         <a href="TF_Product.aspx?id=15">射頻連接器</a> <a href="TF_Product.aspx?id=16">光纖連接器</a>
         <a href="TF_Product.aspx?id=63">轉(zhuǎn)換頭</a>
        </div>
        <p class="menu_head">服務(wù)類</p>
        <div class="menu_body">
         <a href="TF_Product.aspx?id=58">工程建設(shè)類</a> <a href="TF_Product.aspx?id=59">工程維護(hù)類</a>
         <a href="TF_Product.aspx?id=60">軟件類</a>
        </div>
        <p class="menu_head">品牌分銷</p>
        <div class="menu_body">
         <a href="TF_Product.aspx?id=87">華為產(chǎn)品</a>
        </div>
        <p class="menu_head">配件類</p>
        <div class="menu_body">
         <a href="TF_Product.aspx?id=67">配件類</a> <a href="TF_Product.aspx?id=86">標(biāo)準(zhǔn)件</a>
        </div>
        <p class="menu_head">其他</p>
        <div class="menu_body">
         <a href="TF_Product.aspx?id=66">郵費(fèi)差額</a> <a href="TF_Product.aspx?id=69">工程類服務(wù)費(fèi)用</a>
         <a href="TF_Product.aspx?id=78">折扣</a> <a href="TF_Product.aspx?id=88">設(shè)備</a>
        </div>
       </div>
      </td>
      <td width="660" valign="top">
      <div style="border-bottom:1px solid #DFEDFA; padding-left:2%; margin-left:2%;">
      產(chǎn)品類別:<asp:DropDownList ID="ddlProductType" runat="server" DataTextField="pt_name" DataValueField="pt_id">
         </asp:DropDownList>
         
      關(guān)鍵字:<asp:TextBox ID="txtGJZ" runat="server"></asp:TextBox>
         
         <asp:Button ID="btnSel" runat="server" Text="搜索" onclick="btnSel_Click" />
      </div>
      <div> </div>
      <div>
        <asp:Repeater ID="rp" runat="server">
        <ItemTemplate>
         <div style="margin-left:2%; border:1px solid #DFEDFA; padding:3px; margin-top:2px; margin-bottom:3px;">
         <table width="100%">
         <tr height="24px">
         <td rowspan="4" width="90px">
           <asp:Image ID="Image1" ImageUrl="~/Product_pic/NoPic.jpg" runat="server" Width="90px" Height="90px" />
         </td>
         <td width="9px"> </td>
         <td width="60px">產(chǎn)品型號(hào):</td>
         <td><span style="float:left"><%#Eval("pr_guige")%></span><span style="float:right;"><a href="#">查看詳情</a></span></td>
         </tr>
         <tr height="24px">
         <td width="9px"> </td>
         <td>產(chǎn)品編碼:</td>
         <td><%#Eval("pr_bianma")%></td>
         </tr>
         <tr height="30px">
         <td width="9px"> </td>
         <td>產(chǎn)品描述:</td>
         <td><%#Eval("pr_ms")%></td>
         </tr>
         <tr><td height="8px"> </td></tr>
         </table>
         </div>
        </ItemTemplate>
        </asp:Repeater>
        <div style="height:22px; margin-left:2%;" align="right">
        <webdiyer:AspNetPager ID="AspNetPager1" CssClass="anpager" runat="server" FirstPageText="首頁" LastPageText="尾頁" NextPageText="下一頁" PrevPageText="上一頁"
            onpagechanged="AspNetPager1_PageChanged" PageSize="6" ShowMoreButtons="False" ShowPageIndexBox="Never">
          </webdiyer:AspNetPager>
      </div>
      </div>
        
      </td>
     </tr>
    </tbody>
    </table>
    <!--版權(quán)聲明-->
    <table width="878" border="0" align="center">
     <tbody>
     <tr>
     <td>
     <img src="./Index_files/foot_02.gif" usemap="#foot" width="878">
     </td>
     </tr>
     </tbody>
    </table>
    </form>
    </body>
    </html>

    Backend code

    Tb_productsHelper helper = new Tb_productsHelper();
        IList<Tb_productsInfo> list = helper.GetAllListBySql(product_sql);
        this.AspNetPager1.RecordCount = list.Count;//綁定總數(shù)量
        this.AspNetPager1.AlwaysShow = true;
        //先聲明一個(gè)分頁類對(duì)象
        PagedDataSource ps = new PagedDataSource();
        ps.AllowPaging = true;
        ps.PageSize = this.AspNetPager1.PageSize;
        ps.CurrentPageIndex = this.AspNetPager1.CurrentPageIndex-1;
        ps.DataSource = list;
        this.rp.DataSource = ps;
        this.rp.DataBind();

    For more .NET implementation of Repeater control + AspNetPager control paging related articles, please pay attention to the PHP Chinese website!

    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    Hot Topics

    PHP Tutorial
    1502
    276
    Creating and Applying Custom Attributes in C# Creating and Applying Custom Attributes in C# Jul 07, 2025 am 12:03 AM

    CustomAttributes are mechanisms used in C# to attach metadata to code elements. Its core function is to inherit the System.Attribute class and read through reflection at runtime to implement functions such as logging, permission control, etc. Specifically, it includes: 1. CustomAttributes are declarative information, which exists in the form of feature classes, and are often used to mark classes, methods, etc.; 2. When creating, you need to define a class inherited from Attribute, and use AttributeUsage to specify the application target; 3. After application, you can obtain feature information through reflection, such as using Attribute.GetCustomAttribute();

    Designing Immutable Objects and Data Structures in C# Designing Immutable Objects and Data Structures in C# Jul 15, 2025 am 12:34 AM

    The core of designing immutable objects and data structures in C# is to ensure that the state of the object is not modified after creation, thereby improving thread safety and reducing bugs caused by state changes. 1. Use readonly fields and cooperate with constructor initialization to ensure that the fields are assigned only during construction, as shown in the Person class; 2. Encapsulate the collection type, use immutable collection interfaces such as ReadOnlyCollection or ImmutableList to prevent external modification of internal collections; 3. Use record to simplify the definition of immutable model, and generate read-only attributes and constructors by default, suitable for data modeling; 4. It is recommended to use System.Collections.Imm when creating immutable collection operations.

    Creating Custom Middleware in ASP.NET Core C# Creating Custom Middleware in ASP.NET Core C# Jul 11, 2025 am 01:55 AM

    Create custom middleware in ASP.NETCore, which can be implemented by writing classes and registering. 1. Create a class containing the InvokeAsync method, handle HttpContext and RequestDelegatenext; 2. Register with UseMiddleware in Program.cs. Middleware is suitable for general operations such as logging, performance monitoring, exception handling, etc. Unlike MVC filters, it acts on the entire application and does not rely on the controller. Rational use of middleware can improve structural flexibility, but should avoid affecting performance.

    Writing Maintainable and Testable C# Code Writing Maintainable and Testable C# Code Jul 12, 2025 am 02:08 AM

    The key to writing C# code well is maintainability and testability. Reasonably divide responsibilities, follow the single responsibility principle (SRP), and take data access, business logic and request processing by Repository, Service and Controller respectively to improve structural clarity and testing efficiency. Multi-purpose interface and dependency injection (DI) facilitate replacement implementation, extension of functions and simulation testing. Unit testing should isolate external dependencies and use Mock tools to verify logic to ensure fast and stable execution. Standardize naming and splitting small functions to improve readability and maintenance efficiency. Adhering to the principles of clear structure, clear responsibilities and test-friendly can significantly improve development efficiency and code quality.

    Deep Dive into C# Generics Constraints and Covariance Deep Dive into C# Generics Constraints and Covariance Jul 12, 2025 am 02:00 AM

    Generic constraints are used to restrict type parameters to ensure specific behavior or inheritance relationships, while covariation allows subtype conversion. For example, whereT:IComparable ensures that T is comparable; covariation such as IEnumerable allows IEnumerable to be converted to IEnumerable, but it is only read and cannot be modified. Common constraints include class, struct, new(), base class and interface, and multiple constraints are separated by commas; covariation requires the out keyword and is only applicable to interfaces and delegates, which is different from inverter (in keyword). Note that covariance does not support classes, cannot be converted at will, and constraints affect flexibility.

    Best Practices for Using LINQ in C# Effectively Best Practices for Using LINQ in C# Effectively Jul 09, 2025 am 01:04 AM

    The following points should be followed when using LINQ: 1. Priority is given to LINQ when using declarative data operations such as filtering, converting or aggregating data to avoid forced use in scenarios with side effects or performance-critical scenarios; 2. Understand the characteristics of delayed execution, source set modifications may lead to unexpected results, and delays or execution should be selected according to requirements; 3. Pay attention to performance and memory overhead, chain calls may generate intermediate objects, and performance-sensitive codes can be replaced by loops or spans; 4. Keep the query concise and easy to read, and split complex logic into multiple steps to avoid excessive nesting and mixing of multiple operations.

    Understanding C# Async and Await Pitfalls Understanding C# Async and Await Pitfalls Jul 15, 2025 am 01:37 AM

    Common problems with async and await in C# include: 1. Incorrect use of .Result or .Wait() causes deadlock; 2. Ignoring ConfigureAwait(false) causes context dependencies; 3. Abuse of asyncvoid causes control missing; 4. Serial await affects concurrency performance. The correct way is: 1. The asynchronous method should be asynchronous all the way to avoid synchronization blocking; 2. The use of ConfigureAwait(false) in the class library is used to deviate from the context; 3. Only use asyncvoid in event processing; 4. Concurrent tasks need to be started first and then await to improve efficiency. Understanding the mechanism and standardizing the use of asynchronous code that avoids writing substantial blockage.

    Implementing Fluent Interfaces with C# Extension Methods Implementing Fluent Interfaces with C# Extension Methods Jul 10, 2025 pm 01:08 PM

    Fluent interface is a design method that improves code readability and expressivity through chain calls. The core of it is that each method returns the current object, so that multiple operations can be called continuously, such as varresult=newStringBuilder().Append("Hello").Append("").Append("World"). When implementing, you need to combine the extension method and the design pattern that returns this, such as defining the FluentString class and returning this in its method, and creating an initial instance through the extension method. Common application scenarios include building configurators (such as verification rules), checking

    See all articles