In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "what you need to pay attention to when using CLR in C#", the content is simple and clear, and I hope it can help you solve your doubts. Let me lead you to study and learn this article "what you need to pay attention to when using CLR in C#".
1. Performance problems of foreach of C # CLR
The implementation of foreach (string s in rows) {foo (s);} is:
IEnumerator e = rows.GetEnumerator (); try {string s; while (e.MoveNext ()) {s = (String) e.Current; foo (s);}} finally {IDisposable d = e as IDisposable; if (d! = null) d.Dispose ();}
The e.MoveNext () and e.Current methods are called at each step; most of the time, it is entirely possible to optimize to a single call. Obviously, this has an impact on performance. Although foreach makes separate optimizations for arrays (compiled into for loops), this is worth noting.
So, how to do it faster?
For Collection such as List, we can use ForEach (Actionaction), FindAll (Predicatematch), ConvertAll (Converterconverter) and other methods. They are faster, but not all classes that implement IEnumerable provide them.
LINQ pursues compatiblity, not performance. Therefore, the implementation of LINQ completely adopts foreach. It's worth noting.
2. The implementation principle of yield of C # CLR.
The yield keyword is usually used when implementing an object that supports IEnumerable, so that when foreach traverses the object, it can lazy evaluation. For example:
Class MyCollection: IEnumerable {private string s;... Public IEnumerable GetEnumerator () {for (int item0; i2)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.