58.(C#)throw new Exception()
摘要:try{ if(arr.Length >2) { throw new DevideByZeroException(); } } catch (Exception e) {Console.WriteLine(e.Message); }
阅读全文
posted @
2021-07-24 22:20
♩♪♫♬
阅读(63)
推荐(0)
53.(c#)相关工具的使用
摘要:1、使用NUnit建立自动单元测试(集成在VS2010 中了); 2、FXCop工具会获取程序集中的IL代码,并将其与异族编码规则和最佳实践对照分析,最后报告违例情况; 3、ILDasm是一个IL反汇编工具,可以帮助我们洞察细节; 4、Shared Source CLI是一个包含.NET框架内核和C
阅读全文
posted @
2021-07-23 22:58
♩♪♫♬
阅读(79)
推荐(0)
52.(c#)编程风格
摘要:较正规的编程风格 在一个二元操作符的每一边都加一个空格 在每一个逗号后面而不是前面加一个空格 每一个关键字后面加一个空格 一行一个语句 分号前不要有空格 函数的园括号和参数之间不加空格 在一元操作符和操作数之间不加空格 在一个二元操作符的每一边都加一个空格: Consol
阅读全文
posted @
2021-07-23 22:20
♩♪♫♬
阅读(59)
推荐(0)
51.(c#)堆栈 Stack s = new Stack()
摘要:// Stack名字空间namespace Stack{ using System; public class Stack { // first: 栈最上面一个节点 private Node first = null; // count: 栈中节点的数量 private int count = 0;
阅读全文
posted @
2021-07-23 22:14
♩♪♫♬
阅读(152)
推荐(0)
50.(c#)重载操作符= >< !=
摘要:using System; class Rectangle{ private int iHeight; private int iWidth; // 缺省构造函数 public Rectangle() { Height=0; Width=0; } // 构造函数重载 public Rectangle
阅读全文
posted @
2021-07-23 22:12
♩♪♫♬
阅读(86)
推荐(0)
49.(c#)数字位运算:“与”运算,“或”运算,“异或”运算,“求补”运算
摘要:using System; class MyClass{ public static void Main() { int varA = 10; //二进制为 00001010 int varB = 20; //二进制为 00010100 // “与”运算 int andResult = varA &
阅读全文
posted @
2021-07-23 21:59
♩♪♫♬
阅读(159)
推荐(0)
48.(c#)得到某日的下一日(星期几)
摘要:// 声明一个枚举类型Weekday,基类为int,访问范围为public public enum Weekday { Sun, Mon, Tue, Wed, Thu, Fri, Sat } // 功能: 得到某日的下一日(星期几) // 参数: // wd : 枚举类型Weekday // 返回值
阅读全文
posted @
2021-07-23 21:56
♩♪♫♬
阅读(131)
推荐(0)
47.(c#)环境变量中所有的值取出来,放到变量environment中
摘要:using System;using System.Collections; class ForeachApp{ public static void Main() { // 把环境变量中所有的值取出来,放到变量environment中 IDictionary environment = Envir
阅读全文
posted @
2021-07-23 21:51
♩♪♫♬
阅读(63)
推荐(0)
46.(c#)九九乘法表
摘要:using System; class ForApp { public static void Main() { //打印表头 Console.WriteLine("九九乘法表"); //打印九九表 for(int i = 1; i <= 9; i++) { //计算并格式化输出九九表的内容 for
阅读全文
posted @
2021-07-23 21:48
♩♪♫♬
阅读(96)
推荐(0)
45.(c#)以二进制读取文本文件
摘要:using System; using System.IO; public class FileApp { public static void Main() { // 在当前目录创建一个文件myfile.txt,对该文件具有读写权限 FileStream fsMyfile = new FileSt
阅读全文
posted @
2021-07-23 21:43
♩♪♫♬
阅读(181)
推荐(0)
44.(c#)关闭特定程序
摘要:using System;using System.Diagnostics;class close_special_exe{ static void Main() { Process[] myProcess; myProcess=Process.GetProcessesByName ("Notepa
阅读全文
posted @
2021-07-23 21:41
♩♪♫♬
阅读(55)
推荐(0)
43.(c#)随机生成0到100的随机数
摘要:using System;namespace _02_26{ class Class_02_26 { public static void Main() { string sTemp; int iNum=new Random ().Next ()%100; //int i_random=new Ra
阅读全文
posted @
2021-07-23 21:32
♩♪♫♬
阅读(1023)
推荐(0)
42.(c#) switch..case用法
摘要:using System;class ChooseSubject{ static void Main() { int i; string str; Console.WriteLine ("Please choose your favorite subjects:-1 is quit."); Cons
阅读全文
posted @
2021-07-23 21:30
♩♪♫♬
阅读(448)
推荐(0)
41.(c#) 字串变量.Replace("子字串","替换为") ;
摘要:字串变量.Replace("子字串","替换为") 字串替换 如: string str="中国"; str=str.Replace("国","央"); //将国字换为央字 Response.Write(str); //输出结果为“中央” 再如:(这个非常实用) string str="这是<scr
阅读全文
posted @
2021-07-23 21:27
♩♪♫♬
阅读(79)
推荐(0)
40.(c#) char查指定位置是否空字符;查字符是否是标点符号 ;char把字符转为数字,查代码点,注意是单引号
摘要:1.char.IsWhiteSpce(字串变量,位数)——逻辑型 查指定位置是否空字符; 如: string str="中国 人民"; Response.Write(char.IsWhiteSpace(str,2)); //结果为:True, 第一个字符是0位,2是第三个字符。 2.char.IsP
阅读全文
posted @
2021-07-23 21:23
♩♪♫♬
阅读(126)
推荐(0)
39.(c#)存取Session值,用超链接传送变量
摘要:1. Session["变量"]; 存取Session值; 如,赋值: Session["username"]="小布什"; 取值: Object objName=Session["username"]; String strName=objName.ToString(); 清空: Session.
阅读全文
posted @
2021-07-23 21:19
♩♪♫♬
阅读(114)
推荐(0)
38.(c#)取远程用户IP地址
摘要:1.String user_IP=Request.ServerVariables["REMOTE_ADDR"].ToString(); 取远程用户IP地址 2.//穿过代理服务器取远程用户真实IP地址: if(Request.ServerVariables["HTTP_VIA"]!=null){ s
阅读全文
posted @
2021-07-23 21:15
♩♪♫♬
阅读(98)
推荐(0)
36.(c#)DateTime 数字型 取当前年月日时分秒
摘要:1、DateTime 数字型 System.DateTime currentTime=new System.DateTime(); 1.1 取当前年月日时分秒 currentTime=System.DateTime.Now; 1.2 取当前年 int 年=currentTime.Year; 1.3
阅读全文
posted @
2021-07-23 21:09
♩♪♫♬
阅读(481)
推荐(0)
35.(c#)异常处理try ..catch
摘要:xxx try { ...xxx; } catch(Exception ex) { }
阅读全文
posted @
2021-07-23 00:02
♩♪♫♬
阅读(46)
推荐(0)
34.(c#)如何将文本框转换成Enum枚举类型的文本值
摘要:if(!string.IsNullOrEmpty(this.txtStudentName.Text)) { var text = ((int)Enum.Parse(typeof(ENUMTYPE),this.txtStudentName.Text)).ToString(); }
阅读全文
posted @
2021-07-22 23:55
♩♪♫♬
阅读(117)
推荐(0)