简体   繁体   中英

C# dictionary with a float value?

I have values that have decimals that I would like to store in a dictionary for easy access. However in C# it only allows a string and an int. Is there another way I can achieve similar results?

This is my code:

   littledictionary.Add("price", (float)0.0);
   littledictionary["price"] = (float)SQLreader["price"];

What do you mean? You can use a float-based dictionary:

var littledictionary = new Dictionary<string,float>();
littledictionary.Add("price", (float)0.0);

Or alternatively you can use List:

List<Decimal> list1 = new List<decimal>();

You can see how to use lists here: http://www.dotnetperls.com/list

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM