Y
Y
Yura Mailler2021-09-17 08:32:26
C++ / C#
Yura Mailler, 2021-09-17 08:32:26

How to use Dictionary in Unity?

I'm making a store in my game. I found out that there is such a thing as a Dictionary, looked at how it's all done and wrote the following code in the unit:

var Сell = new Dictionary<string, int>(){
      { "Skin1" : 0},
};
But for some reason Visual Studio highlights this code in red. Why and how to solve it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
GavriKos, 2021-09-17
@Yura111

Because a syntax error. Specifically, a colon.
And because you must first learn the language, and then climb into the unit.

V
Vasily Bannikov, 2021-09-17
@vabka

You have a syntax error here

var Сell = new Dictionary<string, int>(){
      { "Skin1" : 0}, // Вот здесь
};

It should be like this:
var cell = new Dictionary<string, int>() {
    { "Skin1", 0 },
};

Either like this:
var cell = new Dictionary<string, int>() {
    ["Skin1"] = 0,
};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question