摘要: 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Net; 6 using System.Net.Sockets; ... 阅读全文
posted @ 2013-07-27 17:45 CodingWang 阅读(317) 评论(0) 推荐(0) 编辑
摘要: using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.IO;namespace ConsoleApplication1{ struct CoOrds { public int x; public int y; } class Program { static void Main(string[] args) { Console.WriteLine("**... 阅读全文
posted @ 2013-07-25 10:41 CodingWang 阅读(194) 评论(0) 推荐(0) 编辑
摘要: using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.IO;using System.Runtime.Serialization.Formatters.Binary;using System.Runtime.Serialization;namespace ConsoleApplication1{ class Program { static void Main(string[] args) { Us... 阅读全文
posted @ 2013-07-25 10:12 CodingWang 阅读(316) 评论(0) 推荐(0) 编辑
摘要: case:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication3{ public class A { public A() { Console.WriteLine("A"); } public A(int x) { Console.WriteLine("A+"); } } pub... 阅读全文
posted @ 2013-04-14 21:41 CodingWang 阅读(114) 评论(0) 推荐(0) 编辑
摘要: 扩展方法的实现方式:定义静态类然后定义静态方法using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ExtensionClass{ class Program { static void Main(string[] args) { object test = new object(); test.ExtensionFun("welcome"); Console.... 阅读全文
posted @ 2013-04-13 14:48 CodingWang 阅读(156) 评论(0) 推荐(0) 编辑
摘要: 结构的声明与class相类似,只是关键字该层struct。结构不支持继承,但是所有的结构都继承与system.ValueType,再继承与system.object。结构的构造函数:结构不允许定义无参数的构造函数,默认构造函数把所有的字段都初始化为0或者null。结构的初始化:struct_example test;test.field1=32;//如果是类则会报错。 阅读全文
posted @ 2013-04-13 14:26 CodingWang 阅读(96) 评论(0) 推荐(0) 编辑
摘要: 编写静态构造函数的原因,类有一些静态字段或者属性,需要在第一次类使用之前,从外部源中初始化这些。不能控制静态构造函数调用的时间,c#其他代码不会调用它,在加载类时,总是由.net运行库调用。因此不能有任何访问修饰符,也不能有任何参数,也只能有一个静态构造函数。 阅读全文
posted @ 2013-04-13 14:18 CodingWang 阅读(92) 评论(0) 推荐(0) 编辑
摘要: 1.#define #undef#define DEBUG 告诉编译器存在给定名称的符号(如果已经存在则不起作用)。#undef DEBUG是删除(如果不存在则不起作用)。int DoSomeWork(int x){ #if DEBUG Console.WriteLine(x); #endif return 0;} 类似的预处理命令还有#elif #else2.#warning #error遇到该指令会分别产生警告和错误。3.#region #endregion折叠代码块。4.#line可以改变编译器在警告和错误信息中显示的文件名和行号信息。5.#pragma可以抑... 阅读全文
posted @ 2013-04-13 10:33 CodingWang 阅读(120) 评论(0) 推荐(0) 编辑
摘要: 重载与重写是C#面向对象的多态性的重要体现。如下面的示例:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{ public class A { public virtual void fun1() { Console.WriteLine("A.fun1"); } public void fun2(B test) { ... 阅读全文
posted @ 2013-04-09 10:47 CodingWang 阅读(136) 评论(0) 推荐(0) 编辑
摘要: string是一个引用类型。string对象被分配在堆上,而不是栈上。因此,当把一个字符串变量赋予另一个字符串时,会得到对内存中同一个字符串的两个引用。但是,string与引用类型在常见的操作上有一些区别。例如,字符串是不可改变的。修改其中一个字符串,就会创建一个全新的对象,而另一个字符串不发生任何变化。 阅读全文
posted @ 2013-04-08 22:15 CodingWang 阅读(134) 评论(0) 推荐(0) 编辑