Y
Y
Yura Mailler2021-09-30 07:10:49
C++ / C#
Yura Mailler, 2021-09-30 07:10:49

Is it possible to do this in Dictionary?

Hello ! (Forgive me if I somehow explained it wrong, I'm just studying Dictionary) Is it possible to do this in Dictionary:

var dictionary = new new Dictionary<string, int>{
       {"Файл" ,  1 , File.png}  //   "имя ячейки" , "Стоимость"  , "Сам файл который пользователь получает при его покупки"
}

You may have noticed that I added File.png , that's my question. Is it possible to add one or two more properties to the cell in this way (or whatever it is called) at the moment I know that only 2 designations can be made: "Cell name", "some kind of cell property". I am making a game and it is necessary that the user switches characters with the buttons and when the button is pressed, the picture changes, the cost is signed (changed), and if the player bought, then the texture (in the example I wrote File.png) will change to the specified one. I told this information just so that you know why I need it and suddenly if you do not understand what I need.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
HemulGM, 2021-09-30
@Yura111

No. A dictionary is a Key, Value list. If you need to store several values ​​by key, then create, for example, a structure and store it as value.

public struct MyStruct
{
     public int ID;
     public string FIleName;
}

MyStruct myFile = new MyStruct();
myFile.ID = 1;
myFile.FileName = "File.png";

var dictionary = new Dictionary<string, MyStruct> {
"Файл1" ,  myFile
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question