U
U
UnityMakar2019-02-24 14:02:43
Unity
UnityMakar, 2019-02-24 14:02:43

How to make a dictionary in Unity like in Pyhton?

Hello!
Help me please, I don't know how to make a dictionary in Unity C# like in python (example): Please tell me how to do it!
d = {'dict': 1, 'dictionary': 2}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
GFX Data, 2019-02-28
@ShockWave2048

It is possible so, types in pair can be any to substitute.

Dictionary<int, StudentName> students = new Dictionary<int, StudentName>()
        {
            { 111, new StudentName { FirstName="Sachin", LastName="Karnik", ID=211 } },
            { 112, new StudentName { FirstName="Dina", LastName="Salimzianova", ID=317 } },
            { 113, new StudentName { FirstName="Andy", LastName="Ruth", ID=198 } }
        };

A
Alexander, 2019-02-24
@NeiroNx

https://metanit.com/sharp/tutorial/4.9.php

D
Denis Gaydak, 2019-02-24
@MrMureno

Alexander , in fact, correctly pointed out to you.
it would only be necessary to make a reservation that in python there are all these immutable)) as pythonists love.
Anything can be a key and anything can be a value, even different types of keys in the layouts of the same dictionary ))
and the dictionary in C # is more strict.
something in the spirit

>>> foo = {42: 'aaa', 2.78: 'bbb', True: 'ccc'}
>>> foo
{42: 'aaa', 2.78: 'bbb', True: 'ccc'}

it will be a little inadequate to turn in the C# dictionary))
here if there is an example)
https://stackoverflow.com/questions/4105361/how-do...
but otherwise everything is the same .. "Key-Value" list, see at least the official documentation, at least an example in other answers))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question