{"id":368,"date":"2017-01-05T12:16:39","date_gmt":"2017-01-05T12:16:39","guid":{"rendered":"https:\/\/ibex.tech\/windows-iot\/?p=368"},"modified":"2022-09-13T15:02:03","modified_gmt":"2022-09-13T14:02:03","slug":"using-list-2","status":"publish","type":"post","link":"https:\/\/ibex.tech\/csharp\/uwp-programming-in-c\/memory-uwp-programming-in-c\/list-memory-uwp-programming-in-c\/using-list-2","title":{"rendered":".Using List"},"content":{"rendered":"<h4>\n\tDeclaring<\/h4>\n<pre><code>\n\tList&lt;byte&gt; LogEvents = new List&lt;byte&gt;();\n\t\/\/or for a class:\n\tList&lt;LogEventClass&gt; LogEvents = new List&lt;LogEventClass&gt;();\n<\/code><\/pre>\n<h4>\n\tAdding Objects<\/h4>\n<pre><code>\n\tLogEventClass LogEvent1 = new LogEventClass();\n\tLogEvents.Add(LogEvent1);\n<\/code><\/pre>\n<h5>\n\tAdd Array<\/h5>\n<pre><code>\n\tLogEvents.AddRange(System.Text.Encoding.UTF8.GetBytes(NameText));\n<\/code><\/pre>\n<h4>\n\tRemoving Objects<\/h4>\n<p>Find the object index then<\/p>\n<pre><code>\n\tLogEvents.RemoveAt(Index);\n<\/code><\/pre>\n<p>There is also RemoveRange or just Remove where you specify an exact match for it to find and remove.<\/p>\n<h4>\n\tTotal Number Of Objects In A List<\/h4>\n<pre><code>\n\tfor (Count = 0; Count &lt; LogEvents.Count; Count++)\n\t{\n<\/code><\/pre>\n<h4>\n\tReading A List Item<\/h4>\n<p>Use an index as with an array.<\/p>\n<pre><code>\n\tSomeVariable = LogEvents[Index];\n<\/code><\/pre>\n<h4>\n\tWorking Through A List<\/h4>\n<pre><code>\n\tfor each (LogEventClass LogEvent in LogEvents)\n\t{\n\t}\n<\/code><\/pre>\n<h4>\n\tClear A List<\/h4>\n<pre><code>\n\tLogEvents.Clear();\n<\/code><\/pre>\n<h4>\n\tConvert List To An Array<\/h4>\n<p>Use .ToArray();<\/p>\n<h4>\n\tCopy An Array To A List<\/h4>\n<pre><code>\n\tList&lt;LogEventClass&gt; LogEvents = new List&lt;LogEventClass&gt;(SomeArray);\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Declaring List&lt;byte&gt; LogEvents = new List&lt;byte&gt;(); \/\/or for a class: List&lt;LogEventClass&gt; LogEvents = new List&lt;LogEventClass&gt;(); Adding Objects LogEventClass LogEvent1 = new LogEventClass(); LogEvents.Add(LogEvent1); Add Array LogEvents.AddRange(System.Text.Encoding.UTF8.GetBytes(NameText)); Removing Objects Find the object index then LogEvents.RemoveAt(Index); There is also RemoveRange or just Remove where you specify an exact match for it to find and remove. Total Number [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[132],"tags":[],"class_list":["post-368","post","type-post","status-publish","format-standard","hentry","category-list-memory-uwp-programming-in-c"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/368","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/comments?post=368"}],"version-history":[{"count":1,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/368\/revisions"}],"predecessor-version":[{"id":1171,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/368\/revisions\/1171"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/media?parent=368"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/categories?post=368"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/tags?post=368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}