自己在开发中的总结

  1. 测试某台机器上是否安装了 .NET Framework 的小程序 - 汽车租赁
  2. .NET 各个版本的版本号和发布日期:

  3. 在一个View 中尽量少用 Html.Action 和 Html.RenderAction ,因为每当一个 Html.Action(或:Html.RenderAction 都用重新New一个对应的Controller)。比如在 Home 的 Index 视图中,使用 “Html.RenderAction("Index","User")”,那么会 New 一个 UserController ,如果 New 很多性能会有影响。
  4. 显示指定枚举变量的值,新增的值放后面就可以了,不要加到开始或中间,枚举最好都显示指定了值。const (常量)也会出现这样的问题,如果类库B引用类库A,有一天类库A代码修改了,建议重新生成A和B,否则枚举和常量有时候会出现问题。所以尽量使用readonly 而不是 const,除非你保证永远不变,比如圆周率之类的。readonly 的好处就是它是运行时常量,修改它时,不必重新编译目标程序。比如:定义一个const的int值, 然后编译, 用dll方式引用。由于编译到dll中的时候, 编译器会优化代码, 不会保存常量名, 而是直接保存值。因此, 下一个人用的时候, 永远是那个值, 即使这面已经改过值了。例如:我写了一个FrameWork, 定义一个常量:public const int MaxValue = 100;然后编译成dll了。 然后你在写程序的时候, 使用了我的framework。并且引用了MaxValue这个值。有一天我发现, 其实我支持的最大值是1000。于是我升级了framework, 变成了:public const int MaxValue = 1000;然后framework发过去。由于程序集版本不升级, 你替换后直接使用了。那么, 你程序中使用MaxValue的地方, 就依然保持100, 而不是1000.
  5. 下面的一段代码编译时,将报警告:为形参"pageIndex"指定的默认值将不起作用,因为应用该值的成员所在的上下文不允许使用可选参数
            // 下面的一段代码编译时,将报警告:为形参"pageIndex"指定的默认值将不起作用,因为应用该值的成员所在的上下文不允许使用可选参数
    IList<CategoryPartial> IDALPager<CategoryPartial, SearchCategory>.GetEntitiesByPager(
    int pageIndex = 1,
    int pageSize = 1,
    SearchCategory searchType = null,
    IEnumerable<string> orders = null)
    {
    throw new NotImplementedException();
    }
  6. 在 ASP.NET 中,web.config 文件中有很多配置节点都有一个 configSource 的属性,利用它来指定 该节点下的元素,比如 appSettings,这样就可以把 appSettings 单独放到某一个 .config 文件中。好处:便于管理。缺点:修改后,不会像修改 web.config 文件后那样立即生效,需要在 IIS 中重启应用网站。比如:
    <appSettings configSource="App_Configs\AppSettings.config">
    </appSettings>

    AppSettings.config:

    <?xml version="1.0"?>
    <appSettings>
      <add key="ClientValidationEnabled" value="true"/>
      <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
    </appSettings>

     

  7. 如果相应使用轻量级泛型集合,可以考虑使用 System.Collections.ObjectModel.Collection<T>
  8. 关于 System.Linq.IGrouping<out TKey, out TElement>  、System.Linq.ILookup<TKey, TElement>  的解析如下:
    IGrouping<out TKey, out TElement>:表示 一个 Key 对应 一个或多个 Value。用 JSON 来演示: { key: 1, value: [ 'a','b','c','d' ] }
    
    ILookup<TKey, TElement>:   一个 或多个 IGrouping<out TKey, out TElement>。用 JSON 来演示: [ { key: 1, value: [ 'a','b','c','d' ] }, { key: 2, value: [ 'a','f','k','m' ] },{ key: 3, value: [ 'p','q','w','t' ] } ]
        // 摘要:
        //     表示具有公共键的对象的集合。
        //
        // 类型参数:
        //   TKey:
        //     System.Linq.IGrouping<TKey,TElement> 的键的类型。
        //
        //   TElement:
        //     System.Linq.IGrouping<TKey,TElement> 的值的类型。
        public interface IGrouping<out TKey, out TElement> : IEnumerable<TElement>, IEnumerable
        {
            // 摘要:
            //     获取 System.Linq.IGrouping<TKey,TElement> 的键。
            //
            // 返回结果:
            //     System.Linq.IGrouping<TKey,TElement> 的键。
            TKey Key { get; }
        }
        // 摘要:
        //     定义索引器、大小属性以及将键映射到 System.Collections.Generic.IEnumerable<T> 值序列的数据结构的布尔搜索方法。
        //
        // 类型参数:
        //   TKey:
        //     System.Linq.ILookup<TKey,TElement> 中的键的类型。
        //
        //   TElement:
        //     组成 System.Linq.ILookup<TKey,TElement> 中的值的 System.Collections.Generic.IEnumerable<T>
        //     序列中的元素的类型。
        public interface ILookup<TKey, TElement> : IEnumerable<IGrouping<TKey, TElement>>, IEnumerable
        {
            // 摘要:
            //     Gets the number of key/value collection pairs in the System.Linq.ILookup<TKey,TElement>.
            //
            // 返回结果:
            //     The number of key/value collection pairs in the System.Linq.ILookup<TKey,TElement>.
            int Count { get; }
    
            // 摘要:
            //     获取按指定键进行索引的值的 System.Collections.Generic.IEnumerable<T> 序列。
            //
            // 参数:
            //   key:
            //     所需值序列的键。
            //
            // 返回结果:
            //     按指定键进行索引的值的 System.Collections.Generic.IEnumerable<T> 序列。
            IEnumerable<TElement> this[TKey key] { get; }
    
            // 摘要:
            //     确定指定的键是否位于 System.Linq.ILookup<TKey,TElement> 中。
            //
            // 参数:
            //   key:
            //     要在 System.Linq.ILookup<TKey,TElement> 中搜索的键。
            //
            // 返回结果:
            //     如果 key 在 System.Linq.ILookup<TKey,TElement> 中,则为 true;否则为 false。
            bool Contains(TKey key);
        }

     

  9. 检查当前运行环境是否是 Mono 环境下:
    private static readonly bool isRunningOnMono = Type.GetType("Mono.Runtime") != null

     

  10. .NET Reflector 下载:点击这里
  11. .NET 下 Web 环境下使用多线程,包括 .NET 4.0 的 Task 时,极其不稳定,很可能某个任务没有执行或者回调函数没有执行,切记在 Web 环境下不要使用!
  12. 谢谢浏览!

转载于:https://www.cnblogs.com/Music/archive/2010/07/26/dotnet-summary.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值