随笔分类 - C#
摘要:创建HttpCookie cookie = new HttpCookie("name"); cookie.Value = HttpUtility.UrlDecode("猪刚烈", Encoding.GetEncoding("UTF-8")); //HttpUtility 这个是用来编码解码的 cookie.Expires = DateTime.Now.AddDays(1); //设置过期时间 Response.Cookies.Add(cookie);读取TextBox1.Text = HttpUtility.UrlDecode(Htt
阅读全文
摘要:首先 本人觉得他们两个很类似,所以我才会说说他们的区别。。 - -相同点:1. 都是object类型的。2. 都是在函数内部声明,看似是局部变量,但是在类中的其他函数也可以使用3.使用方法相同。和session的区别就是:1. session是直接存在硬盘中的而viewstate是存在html文档里的;2. session存储主要是调用的cookie所以存储大小有限制。。貌似是1024k吧。。。viewstate没有。。
阅读全文
摘要:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace lianxi4{ class Program { static void Main(string[] args) { string str = "Welcome to china! this is a beautiful county, i think you will like it.here is The great wall"; str= str.ToLower();//避免出现大小写问
阅读全文
摘要:1、后台生成input的button按钮HtmlGenericControl control = new HtmlGenericControl("input");control.Attributes.Add("type", "button");control.Attributes.Add("onclick",Page.ClientScript.GetPostBackEventReference(this, "btnMyQuery")写入到界面中2、后台回发拦截与处理 if (Page.IsPos
阅读全文
摘要:题目: 有100块钱要买100只鸡 其中 公鸡 5元一只 母鸡 3元一只 小鸡 一元3只 有几种买鸡的方法?用for循环int add = 0; for (int j = 0; j <= 20; j++) //公鸡 { for (int k = 0; k <= 33; k++) // 母鸡 { for (int l = 0; l <= 300; l++) //小鸡 { if (15 * j + 9 * k + l == 300 && j + k + l == 100) { add++; } } } } Console.WriteLine("共有&qu
阅读全文
摘要:冒泡排序:让数组中的元素两两比较(第i个与第i+1个比较),经过若干次两两比较,使得数组中的元素按照我们预期的规律排序。要从大到小排,再量量比较的时候使用<;从小到大使用>10,20,3020,30,101趟2次两两比较30,20,102趟1次两两比较10<20true交换10,20,30,40,50,60,70原始数据7个原素20,30,40,50,60,70,10第1趟比较6次30,40,50,60,70,20,10第2趟比较5次40,50,60,70,30,20,10第3趟比较4次50,60,70,40,30,20,10第4趟比较3次60,70,50,40,30,20,
阅读全文
摘要:\? 问号字符 \’单引号符 \"双引号符 \\反斜线符"\" \0空字符(Null) \a鸣铃 \b退格 \f走纸换页 \n换行 \r回车 \t横向跳到下一制表位置 \v竖向跳格(垂直制表) \ddd任意字符 三位八进制 \xhh任意字符 二位十六进制
阅读全文
摘要:publicstringDateDiff(DateTime endtime,DateTimestarttime){stringdateDiff=null;TimeSpants1=newTimeSpan(endtime.Ticks);TimeSpants2=newTimeSpan(starttime.Ticks);TimeSpants=ts1.Subtract(ts2).Duration();dateDiff=ts.Days.ToString()+"天"+ts.Hours.ToString()+"小时"+ts.Minutes.ToString()+&quo
阅读全文
摘要:用法:String.Format就是和""一样指定一个字符串区别String.Format允许占位符如int X=1;string a="今天是第"+X+"天";string a=String.Format("今天是第{0}天",X);这个格式是直接复制粘贴的。。。。。C#格式化数值结果表字符说明示例输出C货币string.Format("{0:C3}", 2)$2.000D十进制string.Format("{0:D3}", 2)002E科学计数法1.20E+0011.20
阅读全文
摘要:int[] intArr=new int[100];ArrayList myList=new ArrayList();Random rnd=new Random();while(myList.Count<100){int num=rnd.Next(1,101);if(!myList.Contains(num)){myList.Add(num);}for(int i=0;i<100;i++){intArr[i]=(int)myList[i];}
阅读全文
摘要:需要从SQL查询中返回一个值,如表中记录数。可以使用ExecuteScalar()方法,这个方法只返回一个值。如下边控制台应用程序代码所示:usingSystem.Data;usingSystem.Data.SqlClient;namespaceExecuteScalar{classProgram{staticvoidMain(string[]args){SqlConnectionthisConnection=newSqlConnection(@"DataSource=scott;InitialCatalog=northwind;PersistSecurityInfo=True;Us
阅读全文
摘要:C#在Asp.net中实现打开新网页而不关闭当前页Respose.Write("<scriptlanguage='javascript'>window.open('"+url+"');</script>");(打开简洁窗口):Respose.Write("<scriptlanguage='javascript'>window.open('"+url+"','','resizable=1,scrollba
阅读全文

浙公网安备 33010602011771号