c#将Name赋值给integer(以生成唯一的整数)

本文关键字:唯一 整数 Name 赋值 integer | 更新日期: 2023-09-27 18:11:57

我有:

var ItemName = "Item_1_Type_0";
int Stock = 2;

我想使用var Item Name生成一个整数名称,然后分配int值"int Stock"比如:

int Item_1_Type_0 = Stock; 

之后,我需要一种方法来检查stock是否大于0

if( Item_1_Type_0 > 0 ){ 
   // do something 
} //(here i need the encoded variable to replace my example "Item_1_Type_0")

c#将Name赋值给integer(以生成唯一的整数)

你为什么不用字典呢?

var dictionary = new Dictionary<string, int>();
dictionary.Add("Item_1_Type_0" , Stock);

:

if(dictionary["Item_1_Type_0"] > 0)