In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you the example analysis of C# dynamic array, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!
An example of detailed explanation of C# dynamic array:
ArrayList AL = new ArrayList (); AL.Add ("Hello"); AL.Add ("World"); Console.WriteLine ("add elements to the array:"); foreach (Object obj in AL) {Console.Write (obj);} Console.WriteLine (); Console.WriteLine ("number:" + AL.Count); Console.WriteLine ("capacity:" + AL.Capacity); AL.Insert (1, "c #") / / Console.Write ("insert where the index value is 1"); foreach (Object obj in AL) {Console.Write (obj);} Console.WriteLine (); Console.WriteLine ("number:" + AL.Count); Console.WriteLine ("capacity:" + AL.Capacity); AL.Add (") ; / / add "to the collection." To view the capacity of the collection Console.WriteLine capacity : "+ AL.Capacity); AL.Add ("-- "); / / add"-"to the collection to see the multiple change Console.WriteLine (" capacity--: "+ AL.Capacity) when the capacity of the collection is not enough; Console.WriteLine (" Index 3: "+ AL [3]); / / get the detailed instance Console.WriteLine of the collection element value / / C # dynamic array by index (" is it included in the array? " : "+ AL.Contains ("? "); / / use the contains method to find whether the collection contains"? " Console.WriteLine ("array elements after previous operations:"); foreach (Object obj in AL) {Console.Write (obj);} Console.WriteLine (); Console.WriteLine ("number:" + AL.Count); Console.WriteLine ("capacity:" + AL.Capacity); / / detailed AL.Remove (") of the dynamic array of C #. ; / / remove "from the collection." Element AL.Remove ("?"); / / removes "?" from the collection. But because there is no "?" , / so this line of code does not operate on the collection. Console.WriteLine ("No? The number is reduced by only 1 capacity "); foreach (Object obj in AL) {Console.Write (obj);} Console.WriteLine (); Console.WriteLine (" number: "+ AL.Count); Console.WriteLine (" capacity: "+ AL.Capacity) AL.RemoveAt (3); / / remove the element Console.WriteLine of index 3 (" remove the element of index 3: "); foreach (Object obj in AL) {Console.Write (obj) } Console.WriteLine (); Console.WriteLine ("number:" + AL.Count); Console.WriteLine ("capacity:" + AL.Capacity); AL.TrimToSize (); / / reduced capacity Console.WriteLine ("actual capacity:" + AL.Capacity); AL.Clear (); Console.WriteLine ("after all elements are cleared:") Console.WriteLine ("number:" + AL.Count); Console.WriteLine ("capacity:" + AL.Capacity) AL.TrimToSize (); / / reduce capacity Console.WriteLine ("reduce actual capacity again:" + AL.Capacity)
You should have understood the method of sets from the above examples, so let's summarize the advantages of set ArrayList over arrays. The main reason is that it can be dynamically increased according to the size of use, without being controlled by the pre-set size, and that it can add, insert or remove a range of elements at will, which is more convenient than arrays. But it also has its shortcomings, ArrayList no matter what type of object will be added to the collection j, there is no problem at compile time, but in traversal, in order to prevent the type of elements in the collection from being inconsistent, so * use the object type to receive elements traversing j, such as foreach (object i in j), which can reduce errors.
The above is all the content of the article "sample Analysis of C# dynamic Array". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.