01 2013 档案

摘要:使用C#的typeof运算符Type type = typeof(double);使用GetType()方法,所有的类都会从System.Object继承这个方法。如果引用了一个对象,但不能确保该对象实际上是哪个类的实例,这个方法就很有用。double d = 10;Type type = d.GetType();调用Type类的静态方法GetType()。Type type = Type.GetType("System.Double"); 阅读全文
posted @ 2013-01-10 12:26 nil 阅读(435) 评论(0) 推荐(0) 编辑
摘要:using System;namespace exercise { class Program { static unsafe void Main(string[] args) { //创建基于栈的数组 QuickArray 示例 //程序要求用户提供为数组分配的元素数。然后代码使用stackalloc给long型数组分配一定的存储单元。 //这个数组元素是从0开始的整数的平方,结果显示在控制台上: Console.Write("How big an array do you want:... 阅读全文
posted @ 2013-01-10 10:59 nil 阅读(147) 评论(0) 推荐(0) 编辑
摘要:using System;namespace exercise { class Program { static unsafe void Main(string[] args) { //创建基于栈的数组 decimal* pDecimals = stackalloc decimal[10]; int size; size = 20; //or some other value calculated at runtime double* pDoubles = stac... 阅读全文
posted @ 2013-01-10 10:52 nil 阅读(144) 评论(0) 推荐(0) 编辑
摘要:using System;namespace exercise { class Program { static unsafe void Main(string[] args) { //PointerPlayground2 该示例介绍指针的算术,以及结构指针和类成员指针。开始时,定义一个结构CurrencyStruct, //它把货币值表示为美元和美分,再定义一个等价的类CurrencyClass: //查看存储在栈中的项的地址 Console.WriteLine("Szie of Cu... 阅读全文
posted @ 2013-01-10 10:35 nil 阅读(126) 评论(1) 推荐(0) 编辑
摘要:引用类型的分配相当复杂,该博文只说明这两种实例化的区别。static void Main(string[] args) { Customer customer1; customer1 = new Customer();} Customer customer1; 声明一个 Customer引用customer1,会在栈上给这个引用分配存储空间。但这只是一个引用,而不是实际的Customer对象,customer1引用占用4个字节的空间(GetHashCode()返回的是一个int类型)。 customer1 = new Customer(); 这行代码完成了以下操作:首先... 阅读全文
posted @ 2013-01-08 17:31 nil 阅读(802) 评论(2) 推荐(0) 编辑
摘要:在C#中,声明 两个int类型的变量 i 和 j ,有两种声明方式:static void Main(string[] args) { int i; int j;}static void Main(string[] args) { int i, j;} 今天在看《C#高级编程》时,看到了他们的区别,记录下来。 PS:i和j在同一作用域中。 int类型属于值类型,而值类型是存储在栈中的,栈的数据存储属于后进先出(last-in, first-out, LIFO)类型。 对于第一种声明方式,栈指针会先为变量 i 分配空间,再为 j 分配空间,回收空间的时候会先回收 j... 阅读全文
posted @ 2013-01-08 16:25 nil 阅读(784) 评论(3) 推荐(0) 编辑
摘要:Linq 延迟查询 阅读全文
posted @ 2013-01-07 12:21 nil 阅读(190) 评论(1) 推荐(0) 编辑