Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
-3
Question by Ethanbf3 · Feb 20, 2014 at 07:38 PM · c#listtutorial

C# List tutorials & required code

I need a good C# understanding of Lists as I want to perform 2 functions on my List and I don't know how to. I do not want to be spoon-fed the answers because I will not have a understanding. Unity's tutorial on Lists and .NET are to much for me, I do not understand anything they say.

So where can I find out more about Lists so I can perform the functions of Add and display all values of lists while using a item class (The List is a Inventory)

[EDIT] Ok im sorry I was abit frustrated while typing this and now ive calmed down. I will retype this to make it less hostile.

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Hoeloe · Feb 20, 2014 at 07:45 PM 1
Share

"Hey guys! I want to learn how to use lists, but I refuse to use anything that $$anonymous$$ches me how to use lists!"

Seriously, you sound like that. The .NET libraries have very good documentation, including a list of available methods, which you can find here: Link

If you find something on that page that you don't understand, then search for it to try and find an explanation. You will not ever get good at program$$anonymous$$g if you just learn how to do what you need at the time - you need to understand the underlying concepts as well, and that will take time. You should not expect to be able to jump straight into things without having to spend a lot of your time learning.

avatar image Stormizin · Feb 20, 2014 at 07:48 PM 0
Share

Are you trying to learn C# or C# Unity?

avatar image Ethanbf3 · Feb 20, 2014 at 08:16 PM 0
Share

@Hoeloe Ok im sorry I was abit frustrated while typing this and now ive calmed down.

I find .NET to be abit to much and its throwing to much at me.

@Stormizin Erm....C# Unity

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by HuskyPanda213 · Feb 20, 2014 at 08:04 PM

Do not throw aside the unity tutorials they are very good. In short, List.Add works by putting the name of your list(say items), and then doing the add function which takes in the type of class the list has, and then adds it.

 List<Item> Items = new List<Item>();
 
 Item AItem = new Item();
 AItem.Value = 1;
 Items.Add(AItem);

And so on...

Next, displaying a list, this can be achieved with foreach and for loops(with for loops you need to put the item of the list you want to view in [], but that number is usually the number the for loop operates from).

If you do not know how to use foreach loops here is an example/explanation. the loop has the structure

 List<ClassTypeListUses> TheListToUse = new List<ClassTypeListUses>();

 foreach(ClassTypeListUses TempItem in TheListToUse){
 GUILayout.Label(TempItem.Value.ToString());
 }

ClassTypeListUses is what you assigned the lists value to(the class type that is in the ). TempItem is what the item your refering to is, the instance. in is just part of the loop, but IT HAS TO BE THERE, and TheListToUse is the list to get the items from.

for example

 for(int i = 0;i<TheListToUse.count;i++){
 GUILayout.Label(TheListToUse[i].Value.ToString());
 }

And there you have it!

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ethanbf3 · Feb 21, 2014 at 01:39 AM 0
Share

@HuskyPanda213

What is AItem? Also what is each line doing. If it helps my List is called Inventory, my item class is called WorldItemProperties and I wish to access my items by their ItemName variables.

Could you run me through the last 3 lines of code please?

Cheers!

avatar image HuskyPanda213 · Feb 22, 2014 at 03:14 PM 0
Share

LAst three lines of code, a basic forloop that ends at the lists count variable, imagine listtouse has a name/value, that is what value is, and then tostring just makes it a string, this all makes several labels that display each items name.

And AItem would just be an instance of 1 item(in your case WorldItemProperties), which gets added to a list.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How can I get just one componente, or except one, from a list? (string.Join) 0 Answers

Foreach with where with 2 lists 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges