Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

c# dictionaries

Discussion in 'Scripting' started by cybertree, Sep 1, 2015.

  1. cybertree

    cybertree

    Joined:
    Jun 19, 2015
    Posts:
    100
    In Python I remember using dictionaries to make a list of variables so i could later select a random one... How is this done in c#.
     
  2. goonter

    goonter

    Joined:
    Aug 31, 2015
    Posts:
    89
  3. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    What do you mean by 'select a random one'? Via a random integer that was generated by a method? That'd be an array or some kind of list.

    A dictionary in C# is a key-value collection, it's a generic type that allows to you store a value of any type associated with a unique key of any type, that could be a string for example, but also any other type.
     
  4. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    For random selection a list is faster.
     
  5. cybertree

    cybertree

    Joined:
    Jun 19, 2015
    Posts:
    100
    ok then how do you use lists in c#
     
  6. DrSnake

    DrSnake

    Joined:
    Oct 17, 2014
    Posts:
    33
    Kiwasi likes this.
  7. cybertree

    cybertree

    Joined:
    Jun 19, 2015
    Posts:
    100
    that doesn't seem to work. could anyone just put an example with a list and random values from that list. I want the list to be full of game objects
     
  8. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
  9. Timelog

    Timelog

    Joined:
    Nov 22, 2014
    Posts:
    528
    What doesn't work? If you can't seem to use a list make sure you have a using for System.Collections.Generic
     
  10. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    +1, seriously I don't get why people can't google such basic stuff and would rather wait 45 minutes for someone to answer on a forum..
     
  11. cybertree

    cybertree

    Joined:
    Jun 19, 2015
    Posts:
    100
    because pepole can explain better in forums XD
     
  12. cybertree

    cybertree

    Joined:
    Jun 19, 2015
    Posts:
    100
    that is the problem.