{"id":32017,"date":"2024-11-01T09:04:58","date_gmt":"2024-11-01T09:04:58","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=32017"},"modified":"2024-11-01T11:33:41","modified_gmt":"2024-11-01T11:33:41","slug":"unity-basics-course-list-declaration","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/32017\/","title":{"rendered":"Unity Basics Course: List Declaration"},"content":{"rendered":"<p><body><\/p>\n<div class=\"section\">\n<h2>1. Introduction<\/h2>\n<p>Unity is a powerful platform for game development that provides various features to help developers unleash their creativity. In this tutorial, we will learn how to declare and use lists in Unity. Lists are very useful data structures for collecting and managing data, providing the ability to dynamically store and process multiple types of data.<\/p>\n<\/div>\n<div class=\"section\">\n<h2>2. What is a List?<\/h2>\n<p>A list is a collection of data that stores data in a specific order. The greatest advantage of a list is that it allows for easy addition, removal, and sorting of data. In C#, the System.Collections.Generic namespace is used to work with lists. Lists are more flexible than arrays and are useful because their size can be adjusted dynamically.<\/p>\n<ul>\n<li><strong>Dynamic resizing:<\/strong> The size of the list is automatically adjusted as needed.<\/li>\n<li><strong>Random access:<\/strong> You can directly access specific elements of the list through indices.<\/li>\n<li><strong>Variety of methods:<\/strong> Lists provide various methods for adding, deleting, sorting, and searching for elements.<\/li>\n<\/ul>\n<\/div>\n<div class=\"section\">\n<h2>3. Declaring and Initializing a List<\/h2>\n<p>To use a list, you must first declare and initialize it. In C#, you can declare a list as follows:<\/p>\n<pre><code>using System.Collections.Generic;\n\n\/\/ List declaration\nList&lt;Type&gt; listName = new List&lt;Type&gt;();<\/code><\/pre>\n<h3>3.1. Example: Declaring an Integer List<\/h3>\n<pre><code>using System.Collections.Generic;\n\nList&lt;int&gt; integerList = new List&lt;int&gt;();<\/code><\/pre>\n<h3>3.2. Initialization and Adding Data<\/h3>\n<p>After declaring a list, you can initialize it and add data as needed. Here\u2019s how to add data to a list:<\/p>\n<pre><code>integerList.Add(1);\nintegerList.Add(2);\nintegerList.Add(3);<\/code><\/pre>\n<p>This will sequentially add 1, 2, and 3 to the integer list.<\/p>\n<\/div>\n<div class=\"section\">\n<h2>4. Key Methods of a List<\/h2>\n<p>Lists provide various methods to facilitate data manipulation. Here are some commonly used methods:<\/p>\n<h3>4.1. Add() Method<\/h3>\n<p>Used when adding a new element to the list:<\/p>\n<pre><code>integerList.Add(4); \/\/ Add 4 to the list<\/code><\/pre>\n<h3>4.2. Remove() Method<\/h3>\n<p>Used when removing a specific element from the list:<\/p>\n<pre><code>integerList.Remove(2); \/\/ Remove 2 from the list<\/code><\/pre>\n<h3>4.3. Count Property<\/h3>\n<p>Returns the number of elements in the list:<\/p>\n<pre><code>int count = integerList.Count; \/\/ Current number of elements in the list<\/code><\/pre>\n<h3>4.4. Accessing via Indexer<\/h3>\n<p>You can directly access an element at a specific index:<\/p>\n<pre><code>int firstElement = integerList[0]; \/\/ Access the first element<\/code><\/pre>\n<p>The above code retrieves the first element of the integer list.<\/p>\n<\/div>\n<div class=\"section\">\n<h2>5. Iterating Through a List<\/h2>\n<p>You can use the <strong>foreach<\/strong> statement or <strong>for<\/strong> loop to iterate through all the elements in a list. Here\u2019s an example of printing all the elements of a list:<\/p>\n<pre><code>foreach (int number in integerList)\n{\n    Debug.Log(number);\n}<\/code><\/pre>\n<h3>5.1. Accessing Using a For Loop<\/h3>\n<pre><code>for (int i = 0; i &lt; integerList.Count; i++)\n{\n    Debug.Log(integerList[i]);\n}<\/code><\/pre>\n<p>The above codes print all elements of the integer list to the console.<\/p>\n<\/div>\n<div class=\"section\">\n<h2>6. Using Lists with Polymorphism<\/h2>\n<p>Lists can accommodate various data types. For example, you can also add strings or instances of user-defined classes to a list.<\/p>\n<h3>6.1. Example of a String List<\/h3>\n<pre><code>List&lt;string&gt; stringList = new List&lt;string&gt;();\nstringList.Add(\"Hello\");\nstringList.Add(\"Unity\");\nstringList.Add(\"List\");<\/code><\/pre>\n<h3>6.2. Example of a User-Defined Class List<\/h3>\n<p>Here\u2019s how to create a user-defined class and add its instance to a list:<\/p>\n<pre><code>class Player\n{\n    public string name;\n    public int level;\n\n    public Player(string name, int level)\n    {\n        this.name = name;\n        this.level = level;\n    }\n}\n\nList&lt;Player&gt; playerList = new List&lt;Player&gt;();\nplayerList.Add(new Player(\"User1\", 1));\nplayerList.Add(new Player(\"User2\", 2));<\/code><\/pre>\n<\/div>\n<div class=\"section\">\n<h2>7. Conclusion<\/h2>\n<p>In this tutorial, we learned how to declare and use lists in Unity. Lists are important data structures for dynamically managing various data types, and they can be extensively used in game development. By utilizing various methods and properties, lists can be easily manipulated and applied, so it is recommended to use them actively.<\/p>\n<p>Lists may feel simple at first, but understanding how to use them in various situations and the lower-level data structures is very important. Furthermore, by utilizing various collections like sets and dictionaries along with lists, you can significantly enhance programming efficiency.<\/p>\n<\/div>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction Unity is a powerful platform for game development that provides various features to help developers unleash their creativity. In this tutorial, we will learn how to declare and use lists in Unity. Lists are very useful data structures for collecting and managing data, providing the ability to dynamically store and process multiple types &hellip; <a href=\"https:\/\/atmokpo.com\/w\/32017\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Unity Basics Course: List Declaration&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[135],"tags":[],"class_list":["post-32017","post","type-post","status-publish","format-standard","hentry","category-unity-basic"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Unity Basics Course: List Declaration - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/32017\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Unity Basics Course: List Declaration - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"1. Introduction Unity is a powerful platform for game development that provides various features to help developers unleash their creativity. In this tutorial, we will learn how to declare and use lists in Unity. Lists are very useful data structures for collecting and managing data, providing the ability to dynamically store and process multiple types &hellip; \ub354 \ubcf4\uae30 &quot;Unity Basics Course: List Declaration&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/32017\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:04:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:33:41+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"3\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/32017\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32017\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Unity Basics Course: List Declaration\",\"datePublished\":\"2024-11-01T09:04:58+00:00\",\"dateModified\":\"2024-11-01T11:33:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32017\/\"},\"wordCount\":505,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Unity Basic\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/32017\/\",\"url\":\"https:\/\/atmokpo.com\/w\/32017\/\",\"name\":\"Unity Basics Course: List Declaration - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:04:58+00:00\",\"dateModified\":\"2024-11-01T11:33:41+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32017\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/32017\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/32017\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Unity Basics Course: List Declaration\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Unity Basics Course: List Declaration - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/32017\/","og_locale":"ko_KR","og_type":"article","og_title":"Unity Basics Course: List Declaration - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"1. Introduction Unity is a powerful platform for game development that provides various features to help developers unleash their creativity. In this tutorial, we will learn how to declare and use lists in Unity. Lists are very useful data structures for collecting and managing data, providing the ability to dynamically store and process multiple types &hellip; \ub354 \ubcf4\uae30 \"Unity Basics Course: List Declaration\"","og_url":"https:\/\/atmokpo.com\/w\/32017\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:04:58+00:00","article_modified_time":"2024-11-01T11:33:41+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"3\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/32017\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/32017\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Unity Basics Course: List Declaration","datePublished":"2024-11-01T09:04:58+00:00","dateModified":"2024-11-01T11:33:41+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/32017\/"},"wordCount":505,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Unity Basic"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/32017\/","url":"https:\/\/atmokpo.com\/w\/32017\/","name":"Unity Basics Course: List Declaration - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:04:58+00:00","dateModified":"2024-11-01T11:33:41+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/32017\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/32017\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/32017\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Unity Basics Course: List Declaration"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32017","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=32017"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32017\/revisions"}],"predecessor-version":[{"id":32018,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32017\/revisions\/32018"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=32017"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=32017"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=32017"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}