随笔分类 -  C#入门代码

服务器控件验证文本框为空时不回传服务器的简单方法
摘要:首先添加一个新项,这里添加的网页文件名是Default.aspx在Default.aspx里放入两个TextBox,设ID分别为TextBox1和TextBox2.设TextBox2的TextMode属性为Password放入一个Button控件,设ID为Button1,Text属性为"Login"在Ddfault.aspx网页中加入下面代码<script language="javascr... 阅读全文

posted @ 2009-04-11 22:09 VictorShan 阅读(360) 评论(0) 推荐(0)

C#正则表达式备忘
摘要:只能输入n位的数字:"^\d{n}$"。  只能输入至少n位的数字:"^\d{n,}$"。  只能输入m~n位的数字:。"^\d{m,n}$"  只能输入零和非零开头的数字:"^(0|[1-9][0-9]*)$"。  只能输入有两位小数的正实数:"^[0-9]+(.[0-9]{2})?$"。  只能输入有1~3位小数的正实数:"^[0-9]+(.[0-9]{1,3})?$"。  只能输入非零的正整... 阅读全文

posted @ 2008-12-14 16:58 VictorShan 阅读(149) 评论(0) 推荐(0)

快忘记了的C#索引器
摘要://索引器类 class MyArrayList { object[] MyOBJ; //1.定义object类型的数组 int i = 0; public MyArrayList(int i) //2.规定数组长度 { MyOBJ = new o... 阅读全文

posted @ 2008-10-22 00:02 VictorShan

C#:将错误信息写到txt文件中
摘要://以连库为例 SqlConnection con; try { con = new SqlConnection(); con.Open(); return con; } catch(Exception e) ... 阅读全文

posted @ 2008-09-15 17:28 VictorShan 阅读(326) 评论(0) 推荐(0)

C# 判断字符串一是否包含字符串二
摘要:方法一: Console.WriteLine("请输入第一个字符串:"); string str1 = Console.ReadLine(); Console.WriteLine("请输入第二个字符串:"); string str2 = Console.ReadLine(); i... 阅读全文

posted @ 2008-09-03 00:39 VictorShan 阅读(8287) 评论(0) 推荐(0)

C#中的对齐方式
摘要:Console.WriteLine("在宽度为10的空间里靠左对齐:{0,-10}", 99); //显示为:在宽度为10的空间里靠左对齐:99 Console.WriteLine("在宽度为10的空间里靠右对齐:{0,10}", 99); //显示为:在宽度为10的空间里靠右对齐: 99 Console.WriteLine("在宽度为10的空间里靠左对齐:{0,-10}",... 阅读全文

posted @ 2008-09-03 00:17 VictorShan 阅读(3260) 评论(0) 推荐(1)

C#的四个基本技巧 (转载 出处:51cto.com整理)
摘要:1.如果可能尽量使用接口来编程 .NET框架包括类和接口,在编写程序的时候,你可能知道正在用.NET的哪个类。然而,在这种情况下如果你用.NET支持的接口而不是它的类来编程时,代码会变得更加稳定、可用性会更高。请分析下面的代码: private void LoadList (object [] items, ListBox l) { for (int i = 0; i < items.L... 阅读全文

posted @ 2008-09-02 00:05 VictorShan 阅读(234) 评论(0) 推荐(0)

C#读文件代码
摘要:using System; using System.IO; public class TestReadFile { public static void Main(String[] args) { // 创建文件流,读取文件的路径 FileStream fs = new FileStream(@c:\temp\test.txt , Fi... 阅读全文

posted @ 2008-09-01 23:51 VictorShan 阅读(517) 评论(0) 推荐(0)

C#写文件代码
摘要:using System; using System.IO; public class TestWriteFile { public static void Main(String[] args) { // Create a text file C:\temp\test.txt FileStream fs = new FileStrea... 阅读全文

posted @ 2008-09-01 23:48 VictorShan 阅读(1547) 评论(0) 推荐(0)

导航