{"id":700,"date":"2011-12-09T13:36:27","date_gmt":"2011-12-09T13:36:27","guid":{"rendered":"https:\/\/ibex.tech\/visualcpp\/?p=700"},"modified":"2022-02-17T06:24:03","modified_gmt":"2022-02-17T06:24:03","slug":"using-list","status":"publish","type":"post","link":"https:\/\/ibex.tech\/visualcpp\/memory\/list\/using-list","title":{"rendered":".Using List"},"content":{"rendered":"<p>\nUnlike arrays, the List collection type resizes dynamically. &nbsp;If you are working with data where you would need to be resizing an array a lot then use a list instead. &nbsp;It is ideal for linear collections that you don&#39;t need to adjust using an index.\n<\/p>\n<h5>\nGood resources<br \/>\n<\/h5>\n<p>\n<a href=\"http:\/\/www.dotnetperls.com\/list\" target=\"_blank\" rel=\"noopener\">http:\/\/www.dotnetperls.com\/list<\/a>\n<\/p>\n<h4>\nYou need this namespace<br \/>\n<\/h4>\n<pre>\r\n<code>using namespace System::Collections::Generic;<\/code><\/pre>\n<h4>\nDeclaring<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\tList&lt;LogEventClass^&gt; ^LogEvents = gcnew List&lt;LogEventClass^&gt;();\r\n<\/code><\/pre>\n<h4>\nAdding Objects<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\tLogEventClass ^LogEvent1 = gcnew LogEventClass();\r\n\tLogEvents-&gt;Add(LogEvent1);\r\n<\/code><\/pre>\n<h4>\nRemoving Objects<br \/>\n<\/h4>\n<p>\nFind the object index then\n<\/p>\n<pre>\r\n<code>\r\n\tLogEvents-&gt;RemoveAt(Index);\r\n<\/code><\/pre>\n<p>\nThere is also RemoveRange or just Remove where you specify an exact match for it to find and remove.\n<\/p>\n<h4>\nTotal Number Of Objects In A List<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\tfor (Count = 0; Count &lt; LogEvents-&gt;Count; Count++)\r\n\t{\r\n<\/code><\/pre>\n<h4>\nReading A List Item<br \/>\n<\/h4>\n<p>\nUse an index as with an array.\n<\/p>\n<pre>\r\n<code>\r\n\tSomeVariable = LogEvents[Index];\r\n<\/code><\/pre>\n<h4>\nWorking Through A List<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\tfor each (LogEventClass ^LogEvent in LogEvents)\r\n\t{\r\n\t}\r\n<\/code><\/pre>\n<h4>\nClear A List<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\tLogEvents-&gt;Clear();\r\n<\/code><\/pre>\n<h4>\nConvert List To An Array<br \/>\n<\/h4>\n<p>\nUse -&gt;ToArray();\n<\/p>\n<h4>\nCopy An Array To A List<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\tList&lt;LogEventClass^&gt; ^LogEvents = gcnew List&lt;LogEventClass^&gt;(SomeArray);\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Unlike arrays, the List collection type resizes dynamically. &nbsp;If you are working with data where you would need to be resizing an array a lot then use a list instead. &nbsp;It is ideal for linear collections that you don&#39;t need to adjust using an index. Good resources http:\/\/www.dotnetperls.com\/list You need this namespace using namespace System::Collections::Generic; [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[79],"tags":[],"class_list":["post-700","post","type-post","status-publish","format-standard","hentry","category-list"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/700","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/comments?post=700"}],"version-history":[{"count":11,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/700\/revisions"}],"predecessor-version":[{"id":1621,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/700\/revisions\/1621"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/media?parent=700"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/categories?post=700"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/tags?post=700"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}