随笔分类 -  C#

摘要:C#为了类型安全,默认并不支持指针。但是也并不是说C#不支持指针,我们可以使用unsafe关键词,开启不安全代码(unsafe code)开发模式。在不安全模式下,我们可以直接操作内存,这样就可以使用指针了。在不安全模式下,CLR并不检测unsafe代码的安全,而是直接执行代码。unsafe代码的安全需要开发人员自行检测。一、Vs2010中开启unsafe code 的方式在方法、类、代码块中使用unsafe关键词,如:unsafe static void Main(string[] args){ //代码}unsafe{//代码块}然后再项目上点击鼠标右键,选择“属性”,在“生成”选项卡中选 阅读全文
posted @ 2013-08-15 10:21 zzlp 阅读(685) 评论(0) 推荐(0)
摘要:如有一个如下类:class EquipmentPiece { private: int IDNumber; public: EquipmentPiece(int IDNumber) : IDNumber(IDNumber) {}; };以下列出几种初始化的方法:、对象数组int ID1, ID2, ID3; EquipmentPiece bestPieces[] = { EquipmentPiece(ID1), EquipmentPiece(ID2), EquipmentPiece(ID3) };注意:EquipmentPiece bestPieces[10];//no appropriate 阅读全文
posted @ 2013-08-14 14:22 zzlp 阅读(898) 评论(0) 推荐(0)
摘要:public static bool ObjectEquel(TempClass obj1, TempClass obj2) { Type type1 = obj1.GetType(); Type type2 = obj2.GetType(); System.Reflection.PropertyInfo[] properties1 = type1.GetProperties(); System.Reflection.PropertyInfo[] properties2 = type2.GetProperties(); bool IsMatch = true; for (int i =... 阅读全文
posted @ 2013-08-14 11:04 zzlp 阅读(2474) 评论(0) 推荐(0)
摘要:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.IO;namespace ConsoleApplication1{ public class INFO { public Int32 a { get; set; } public string b { get; set; } public string c { get; set; } ... 阅读全文
posted @ 2013-08-09 10:36 zzlp 阅读(410) 评论(0) 推荐(0)