随笔分类 -  C#

摘要:其实网上有挺多实现鼠标滚轮支持的文章,原理都一样,通过 HtmlPage.Window.AttachEvent("DOMMouseScroll", ...)来对ScrollViewer进行控制,但许多却仅限于对ScrollViewer添加滚轮支持,而对TextBox、ListBox这样的控件 好像挺没辙的。使用Reflector看TextBox和ListBox的实现,发现他们内部都有一个field... 阅读全文

posted @ 2009-02-13 10:54 Adrian H. 阅读(1454) 评论(4) 推荐(0)

摘要:MSDN博客中的一篇文章提到了.NET 3.5 SP1会带来的处个修正,见以下代码:var floats = new ArrayList { 2.5f, 3.5f, 4.5f };var ints = from int i in floats select i;注意from后面声明的显式类型(int)。开发者会很自然地认为ints为[2,3,4],但在现在版本.NET 3.5环境下得到的却是[2,... 阅读全文

posted @ 2008-02-16 23:07 Adrian H. 阅读(1305) 评论(0) 推荐(0)

摘要:C#小组Charlie Calvert在其博客发了一篇有关C#语言未来方向的文章,这片文章介绍了一个叫做动态查找的特性,它为.NET语言(包括建立在DLR上的语言)能有一个统一的动态运行时名称绑定方案,让C#能与其他.NET动态语言(如IronPython和IronRuby)进行交互。它的应用场景包括: 办公自动化:其实就是能更方便得调用Office的COM Interop,避免了膨... 阅读全文

posted @ 2008-02-05 21:23 Adrian H. 阅读(1094) 评论(1) 推荐(0)

摘要:The Volta technology preview is a developer toolset that enables you to build multi-tier web applications by applying familiar techniques and patterns. First, design and build your application as... 阅读全文

posted @ 2007-12-06 11:19 Adrian H. 阅读(597) 评论(0) 推荐(0)

摘要:匿名对象一般只在同一个Scope中定义和使用, 这样才能让VS有Intellisence: 如果是通过函数传递过来的匿名类型对象, 就只能用object来传了..当然也就没了Intellisense: 但... 从Meta-Me上面看到一个Trick..虽然不太雅观...但在关键时刻可以帮你把类型信息拯救回来: 原理很简单: 同一结构的匿名类型在同一程序集中编译器只会产生一个, 但匿名... 阅读全文

posted @ 2007-11-22 16:27 Adrian H. 阅读(8977) 评论(5) 推荐(1)

摘要:扩展方法本质上只是一个编译器级别的语法糖, 但不引用.NET Framework 3.5的程序集却无法发布程序到 2.0/3.0版本的运行环境中, 因为它将使那些方法(扩展方法)带上ExtensionAttribute属性, 而就是 ExtensionAttribute这个类却存在于.NET Framework 3.5的程序集中. 其实只要使用一个小技巧即可以保证带有扩展方法的程序在Target到.NET Framework 2.0/3.0时通过编译... 阅读全文

posted @ 2007-11-17 22:19 Adrian H. 阅读(1070) 评论(0) 推荐(0)

摘要:??可能是一个被遗忘的运算符,很少看到有人用它,它的用法很简单却很实用 阅读全文

posted @ 2007-09-29 11:30 Adrian H. 阅读(5043) 评论(11) 推荐(0)

摘要:NSweetie是一个轻量, 高效, 方便的数据访问组件. 用户创建好数据库后, 只需要提供数据操作的接口定义, 输入什么参数以及得到什么数据或实体, 其他的事情全部交给NSweetie吧! 组件不是魔法, 依然需要生成代码, NSweetie生成的代码的方式是通过System.Reflection.Emit的API直接生成MSIL, 用户看不到任何CSharp代码.. 其实, 也不需要看到.... 阅读全文

posted @ 2007-09-07 17:20 Adrian H. 阅读(2434) 评论(10) 推荐(0)

摘要:LINQ TO SQL作为一个对SQL Server特性完全支持的数据访问组件, 强大也是要付出性能代价的, 于是我想自己实现一个类似的组件, 这两天连续设计和编码, 基本实现了预定的功能, 包括对定义的实体的CRUD操作, 存储过程的代码生成. 组件的使用者只需要编写类, 定义实体的各个属性以及对应表, 列属性, 组件可以动态生成从SqlDataReader到实体的映射代码, 所谓动态是通过在运行时Emit IL, 获取这一段映射的代码, 通过良好的类层次设计只需要Emit所需要的很少量的中间代码, 对于一个实体类型只需要生成一次, 许多Emit过程所必要的对象都缓存在了static字段中, 所以Emit的过程是很高效的, 使用Profiler可以看到生成一个对于的类型只需要几十ms~100ms左右; 对于存储过程, 用户提供一个存储过程对于的接口, 组件将提供一个实现该接口的对象, 用户则可以使用它很方便的调用存储过程. 阅读全文

posted @ 2007-08-25 09:05 Adrian H. 阅读(1619) 评论(7) 推荐(0)

摘要:C# code snippet below is an illustration of the Cooky-Turkey algorithm, the performance may suck when processing huge datasets, but you can use arrays of double instead of arrays of complex number structure to reduce the performance impact by object initializations and method invocations(overloaded operators). 阅读全文

posted @ 2007-08-10 15:30 Adrian H. 阅读(3235) 评论(3) 推荐(0)

摘要:PGM(Portable Gray Map) is an image format which uses 1 or 2 byte to store a grayscale pixel, the format specification is simple and straight forward, detail specification can be seen here So, writing a simple converter from PGM to the most common used BMP format is really an easy job. 阅读全文

posted @ 2007-08-07 13:56 Adrian H. 阅读(3120) 评论(1) 推荐(1)

摘要:介绍几个未公开的C#关键字, 好像没什么大用处, 只是了解了CLI的一些东西 阅读全文

posted @ 2007-07-25 02:26 Adrian H. 阅读(1590) 评论(2) 推荐(0)

摘要:The source code demonstrates a basic principle of these two compression algorithms[Download]Note: The LZW compression class is implemented as a fixed length code which you can specify, the huffman alg... 阅读全文

posted @ 2007-06-27 22:00 Adrian H. 阅读(5817) 评论(2) 推荐(0)

摘要:Visual Studio codename Orcas beta 1 都出来了, 感受一下带有新语法特性的 C# 3.0 吧. 有人觉得新语法很杂, 甚至觉得 C# 越来越不像它自己了, 其实... 它一点都没变... 阅读全文

posted @ 2007-05-19 10:47 Adrian H. 阅读(4326) 评论(11) 推荐(0)

摘要:This is a tutorial on using Functional Programming (FP) techniques for constructing LINQ queries. It is certainly possible to write simple LINQ queries without using these techniques, but as soon as you start writing more complicated queries, you need to understand these techniques. 阅读全文

posted @ 2007-04-13 12:17 Adrian H. 阅读(818) 评论(0) 推荐(0)

摘要:操作系统概念中"哲学家就餐问题"的C#模拟 阅读全文

posted @ 2007-04-01 19:04 Adrian H. 阅读(1840) 评论(0) 推荐(0)

摘要:结论是: 有的产生, 有的不产生 阅读全文

posted @ 2007-03-18 15:36 Adrian H. 阅读(637) 评论(0) 推荐(0)

摘要:一种避免由于Delegate造成引用导致GC无法回收被引用对象的办法.. 阅读全文

posted @ 2007-03-11 20:34 Adrian H. 阅读(1939) 评论(6) 推荐(8)

摘要:Scott Guthrie介绍的C# 3.0中的语言新特性 阅读全文

posted @ 2007-03-11 11:24 Adrian H. 阅读(478) 评论(0) 推荐(0)

摘要:const 和 static readonly看起来挺像的, 但它们还是有区别的, const值要在编译时就使用常量初始化, 不能在运行时修改, 而static readonly值可以在编译器动态初始化, 但初始化之后也不能修改. 这是它们的区别, 对于const值编译器会有一些优化, 但这些优化在某些情况下可能导致错误.假如现在有两个工程, 其中有一个Class Library, 里面有个类: ... 阅读全文

posted @ 2006-10-28 11:31 Adrian H. 阅读(502) 评论(1) 推荐(0)