惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
B
Blog RSS Feed
The GitHub Blog
The GitHub Blog
Recent Announcements
Recent Announcements
A
About on SuperTechFans
G
Google Developers Blog
aimingoo的专栏
aimingoo的专栏
U
Unit 42
WordPress大学
WordPress大学
Y
Y Combinator Blog
罗磊的独立博客
J
Java Code Geeks
Microsoft Azure Blog
Microsoft Azure Blog
腾讯CDC
博客园 - 叶小钗
Stack Overflow Blog
Stack Overflow Blog
Engineering at Meta
Engineering at Meta
Microsoft Security Blog
Microsoft Security Blog
GbyAI
GbyAI
V
V2EX
雷峰网
雷峰网
H
Hackread – Cybersecurity News, Data Breaches, AI and More
S
SegmentFault 最新的问题
酷 壳 – CoolShell
酷 壳 – CoolShell

博客园 - 分享 共赢

大爱,netbeans的远程开发 lvs + keepalived udp小结 web项目下,甩开RazorTemplateEngine做模板处理 将watin的ui单元测试集成到cc.net 命令行发布web项目 Microsoft © SilverlightTM Release History 针对sl的ICSharpCode.SharpZipLib,只保留zip,gzip的流压缩、解压缩功能 不同IComparer对数组排序Array.Sort,Linq orderby的性能的影响 高效获取某个数字的最后2位 centos asp.net运行环境配置 扣出MSLinqToSQLGenerator的基类,可用于开发自定义工具(custom tool) [转]我在微软做PM ... Linq to sql 简单性能差异指引 April Rosario(vs2010?) CTP now available! 手工杀毒利器 在form上设定了defaultbutton属性之后,切换提交按钮的解决办法 在form上设定了defaultbutton属性之后,切换提交按钮的解决办法 Bingo Day-展示自我,共享成功! 使用System.Net.Mail发送邮件,vs2005与vs2008存在差别?
c# 编译器优化的功劳?与泛型有关的代码的疑惑
分享 共赢 · 2010-01-11 · via 博客园 - 分享 共赢

  在我设计的一部分代码中,有自定义序列化对象的代码如下:

代码

forint i = 0; i < this.Entities.Length; i++ )
{
    
//这里当T是结构类型时还是可以正常处理,实际上结构体是不能与null进行比较的
    
//或许当编译系统编译的时候把判断条件优化掉了,也就是说不会有this.Entities[ i ] == null的判断
    ifthis.Entities[ i ] == null )
    {
        stream.WriteByte( 
0 );//null
        continue;
    }
    
else
    {
        stream.WriteByte( 
1 );//not null
        WriteEntity( stream, this.Entities[ i ] );
    }
}

其中Entities的定义为public T[] Entities { get; set; },当我序列化类的实例或结构的实例均可正常工作。

暂时找不出原因,只能做上述的猜测。