C#知识点

1.global::表示所有命名空间的根部,global后面的实际上就是从最顶层开始向下的命名空间路径,这样可以精确地定位需要访问的类。

2.The CultureInfo class now has a DefaultThreadCurrentCulture and DefaultThreadCurrentUICulture. When set, it will be used to initialize the culture of any managed thread instead of the default Windows system culture.这样可以让后台线程使用UI线程的CultureInfo.

3.possible multiple enumeration of IEnumerable

 

var test = Enumerable.Range(1, 100);

var a = test.Where(n => n%2 == 0);

var b = a.Sum();

var c = a.Count();

var d = from x in a where x%2 == 0 select x;



The test is a Enumerable from 1 to 100. The a variable returns the even numbers between 1 to 100 (however, it is just a query and it does not run immediately).
The variables b, c, and d will run multiple queries (3 times). If the number of dataset is large that certainly there will be a performance bottleneck.
To easy way to fix this is to cache the query result by simply adding a ToList() or ToArray() after LINQ so that the query result is saved (cached).

 

你可能感兴趣的:(C#)