myAdBanner
2013年9月14日 星期六
c# 判斷字串是否為空值IsNullOrEmpty
若有一個字串為空值,例如:
string a="";
string b=null;
string c=string.Empty;
所以要判斷a、b、c是否為空值,可以使用IsNullOrEmpty來判斷,所以上面三個字串,其結果皆為true。
string.IsNullOrEmpty(a) = true;
string.IsNullOrEmpty(b) = true;
string.IsNullOrEmpty(c) = true;
上一篇下一篇
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>.cs頁面無標題頁
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class _Default : System.Web.UI.Page { CommonClass CC = new CommonClass(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string id = Request["id"].ToString(); bindNext(Convert.ToInt32(id)); } } private void bindNext(int id) { int lastid = id - 1; int nextid = id + 1; this.ViewState["NextDetails"] = nextid.ToString(); this.ViewState["lastid"] = lastid.ToString(); this.ViewState["nextid"] = nextid.ToString(); if (lastid > 0) { string sql = "select * from news where id=" + lastid + ""; DataSet ds = CC.GetDataSet(sql, "dttit"); DataRow[] row = ds.Tables["dttit"].Select(); foreach (DataRow rs in row) { this.lbName.Text = rs["title"].ToString(); this.lkLast.Text = rs["title"].ToString(); this.ViewState["lastDetails"] = rs["content"].ToString(); } } else { this.lkLast.Text = "已經是第一篇"; } string sql1 = "select * from news where id=" + nextid + ""; DataSet ds1 = CC.GetDataSet(sql1, "dttit"); DataRow[] row1 = ds1.Tables["dttit"].Select(); foreach (DataRow rs1 in row1) { this.lbName.Text = rs1["title"].ToString(); this.lkNext.Text = rs1["title"].ToString(); this.ViewState["nextDetails"] = rs1["content"].ToString(); } } protected void lkLast_Click(object sender, EventArgs e) { this.LbDetails.Text = this.ViewState["lastDetails"].ToString(); int id = Convert.ToInt32(this.ViewState["lastid"].ToString()); bindNext(id); } protected void lkNext_Click(object sender, EventArgs e) { this.LbDetails.Text = this.ViewState["nextDetails"].ToString(); int id = Convert.ToInt32(this.ViewState["nextid"].ToString()); bindNext(id); } }
訂閱:
文章 (Atom)