c# 各种tips

1.lock 类似于 java中的synchronized,对对象或代码块加上互斥锁。

2.c#中的lambda表达式, ForEach(x => f(n))

3.c# 中的 something?.method  的含义是 如果something是null,返回null, 否则返回something的method,或者属性。

4.c# static readonly: https://www.cnblogs.com/qingxia/archive/2011/02/10/1950741.html 运行时赋值, Const 编译时赋值。

5.c# System.Threading.CancellationToken(其IsCancellationRequested方法),从外部控制一个线程(task)的停止,使用方式是在task内部判断isCancellationRequested是否为真。

6.c#中的 #region  #endregion 代码折叠,没啥卵用。

7.c#中的 ActionBlock,BroadcastBlock

8.c#中的序列化反序列化(二级制和stream,json)

9.c# threading.LongRunningTask

10.c# 中的Diagnostics中的stopWatch

11.c#中Autofac IOC的使用。

 

12 

Action<SqlConnection, SqlTransaction> delAction = (SqlConnection conn, SqlTransaction tran) =>
            {
                var sqlCmd = new SqlCommand(sql, conn) { Transaction = tran };
                sqlCmd.ExecuteNonQuery();
            };
                    var insertAction = SqlUtility.GetBulkInsertAction(filteredItems, tableName);
                    SqlUtility.ExcuteTransaction(config.DbConnStr, new[] { delAction, insertAction });

 

posted on 2018-04-13 13:39  重八  阅读(301)  评论(0编辑  收藏  举报

导航