0

I am re-learning how to code, but with a new-ish language; please forgive if this or any questions I ask seem a little off the wall.

As the title says. I don't have any code as of yet, but I find that I want to create an array that keeps track of an item name and the weight of said item on the same index. So what I want to do is create something like

array[string[] ItemName, int ItemWt[]];

Looking at this maybe I need a struct, but I haven't figured those out in C# with forms development, yet.

I am using Microsoft's Visual Studio 2019.

user2864740
  • 60,010
  • 15
  • 145
  • 220
  • 1
    Take a look on: https://stackoverflow.com/questions/1939443/defining-two-dimensional-dynamic-array-with-different-types – Mohamed Farouk Jan 20 '20 at 01:17
  • All elements of an array, multidimensional or not, must have the same unified static type. (The same also holds for other collection types like Lists.. use aggregate objects as relevant.) – user2864740 Jan 20 '20 at 01:24
  • Thank you. I was looking for arrays and didn't see anything for lists. But that helps. Thanks again. – PurpleDragon Jan 20 '20 at 01:24
  • You need a collection of classes, not of structs. – Dour High Arch Jan 20 '20 at 01:31
  • Create a class (`public class Item { public string Name {get; set;}; public int Weight {get; set;}}`). Create instances of your items and add them to a collection (you'll be happier with a `List` than an array of Items) – Flydog57 Jan 20 '20 at 02:05

0 Answers0