Search Unity

benannte werte in einem array / in einer list C#

Discussion in 'Scripting' started by Leo-Prislin, Jan 15, 2019.

  1. Leo-Prislin

    Leo-Prislin

    Joined:
    Jan 13, 2019
    Posts:
    4
    Hey,
    ist es irgendwie möglich ein Array oder eine List in C# zu machen in dem die Werte nicht einfach durchnummeriert sind sondern benannt werden?
    Also nicht so:
    Code (CSharp):
    1. List<string> list1 = new List<string>();
    2. list1.add("hello");
    3. // hello == list1[0]
    Sondern eher so:
    Code (CSharp):
    1. List<string> list2 = new List<string>();
    2. list2.add("greeting", "hello");
    3. Debug.Log(list2.greeting);  // Console: hello
    4.  
    Also ähnlich wie bei PlayerPrefs.
    Danke für alle Antworten!

    Here the same again in English: (Sorry for my bad english skills)
    Hey,
    is it possible to make an Array or a List in C#, in wish you can safe your values are named instead of numbered?
    For Example, Instead of writing this:
    Code (CSharp):
    1. List<string> list1 = new List<string>();
    2.  
    3. list1.add("hello");
    4. Debug.Log(list1[0])  // Console: hello
    5. Maybe you can write something like this:
    6. [code=CSharp]List<string> list2 = new List<string>();
    7.  
    8. list2.add("greeting", "hello");
    9.  
    10. Debug.Log(list2.greeting);  // Console: hello
    11.  
    12.  
    Ist similar to PlayerPrefs.
    Thanks for your replies!
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
    Sounds like you want a dictionary to which a key/value pair is created.

    https://docs.microsoft.com/en-us/do....generic.dictionary-2?view=netframework-4.7.2

    They show an example of a <string, string> dictionary
     
    Kurt-Dekker likes this.
  3. Leo-Prislin

    Leo-Prislin

    Joined:
    Jan 13, 2019
    Posts:
    4