C#委托的用法(原创)--王超C#

摘要: delegate int p(int i,int j); static int p1(int i, int j) { return i + j; } static int p2(int i, int j) { return i - j; } static void Main(string[] args) { int i = 10; int j = 9; p pp; ... 阅读全文
posted @ 2013-01-18 14:54 王超 阅读(142) 评论(0) 推荐(0)

C#函数的用法总结(原创)--王超C#

摘要: 1,函数中有return立刻结束函数体:static void Main(string[] args) { w(); int i = 1; } static void w() { return; int k = 2; }2,如果有返回类型,则必须运行returnstatic void Main(string[] args) { w(1); } stat... 阅读全文
posted @ 2013-01-18 14:37 王超 阅读(300) 评论(0) 推荐(0)

C#的split()函数的用法(原创)--王超C#

摘要: split()函数是用来分隔一个字符串变成一个字符串数组:1.用空格分隔字符串:(单个字符分隔)string a = "i am a person"; string[] b; b = a.Split(' '); foreach (string k in b) { Console.WriteLine(k); } Console.ReadKey();2.多个字符分隔:用char数组string a = "ixyamyaxperson"; ... 阅读全文
posted @ 2013-01-18 13:29 王超 阅读(648) 评论(0) 推荐(0)

C#字符串的处理(原创)--王超C#

摘要: 字符串string可以看成char类型的只读数组,不能赋值,只能读值。string a = "abcdefg"; for (int i = 0; i < a.Length; i++) { Console.WriteLine(a[i]); } Console.ReadKey();可以用ToCharArray()把只读数组改为可写数组;string a = "abcdefg"; for (int i = 0; i ... 阅读全文
posted @ 2013-01-18 10:40 王超 阅读(248) 评论(0) 推荐(0)

C#锯齿数组的用法(原创)--王超C#

摘要: 之前讨论的都是矩阵数组,现在需要每列元素个数不同的情况:我们可以理解为,一个数组里面每一个元素还是个数组:3种赋值方法:int[][] a = new int[2][]; a[0] = new int[3]; a[1] = new int[4]; int[][] b = new int[2][] { new int[]{1,2,3},new int[]{4,5,6,7}}; int[][] c = { new int[3]{1,2,3},new int[4]{4,5,6,7}};我们遍历每个元素,可以用fo... 阅读全文
posted @ 2013-01-17 17:55 王超 阅读(3527) 评论(1) 推荐(0)

C#多维数组用法(原创)--王超C#

摘要: int[,] a={{1,2,3},{4,5,6}}; //错误写法a={{1,2,3},{4,5,6}}; Console.WriteLine(a[1,1]); Console.ReadKey();我们声明一个二维数组,有三种赋值方式:int[,] a = { {1,2,3},{4,5,6}}; int[,] b = new int[,] { { 1, 2, 3 }, { 4, 5, 6 } }; int[,] c = new int[2, 3] { { 1, 2, 3 }, { ... 阅读全文
posted @ 2013-01-17 17:34 王超 阅读(647) 评论(0) 推荐(1)

C#数组用法(原创)--王超C#

摘要: 数组的声明int[] arr1; int[] arr2 = { 1,2,3}; int[] arr3 = new int[3]; int[] arr4 = new int[3] { 1, 2, 3 }; const int k = 10; int[] arr5 = new int[k];对于数组,for和foreach的区别:for可以修改,foreach为只读string[] a = { "aaa","bbb","ccc"}; for(int i = 0; i ... 阅读全文
posted @ 2013-01-16 17:50 王超 阅读(192) 评论(0) 推荐(0)

C#的结构体用法(原创)--王超C#

摘要: enum sex { nan=3, nv } struct wang { public sex s; public string name; } class Program { static void Main(string[] args) { //sex w = sex.nan; int i = 4; sex k = (sex)i; wang w; w.na... 阅读全文
posted @ 2013-01-16 17:08 王超 阅读(185) 评论(0) 推荐(0)

C#的枚举用法(原创)--王超C#

摘要: enum sex { nan,nv } class Program { static void Main(string[] args) { sex w = sex.nan; Console.WriteLine(w); Console.ReadKey(); } }不要觉得制定nan=3没什么用,其实可以判断的.enum sex { nan=3, nv } class Program { ... 阅读全文
posted @ 2013-01-16 16:41 王超 阅读(157) 评论(0) 推荐(0)

C#数据类型转换(原创)--王超C#

摘要: 数据类型转换--分为:隐式转换 和 显式转换隐式转换规则:类型A取值范围 < 类型B, A就可以 隐式转换 为B常用:char =》int ,long,float,double。。。int=》long,float,double,decimal。。。char a = 'a'; int b = a; Console.WriteLine(b); Console.ReadKey();byte存储0—255,而short存储0—32767byte转short,没问题,但是short转byte,需要注意(short在255以下的可以转byt... 阅读全文
posted @ 2013-01-16 15:56 王超 阅读(237) 评论(0) 推荐(0)