SwiperNo
SwiperNo

Reputation: 79

C# Adding doubles and ints to a list

Noob logic student here.

How do you add doubles and ints to a list? I still have a hard time reading Microsoft's guide.


    public static List<string> salesCustomerName = new List<string>();
    public static List<string> salesItemDescription = new List<string>();
    public static List<double> salesItemPrice = new List<double>();
    public static List<int> salesQuantity = new List<int>();


    public static void ReadItems() {
      // use a StreamReader to read data from items.csv 
      string filename = "data/items.csv";
      if (File.Exists(filename)) {
      using (var reader = new StreamReader(filename)){
        reader.ReadLine();
        while (!reader.EndOfStream) {
          var line = reader.ReadLine();
          var values = line.Split(",");
          salesCustomerName.Add(values[0]);
          salesItemDescription.Add(values[1]);
          salesItemPrice[2].Add();
          salesQuantity.AddInt();
      }
    }
   } else {
    Console.WriteLine($"{filename} does not exist");
        }
      // populate the items lists
      SaveItems();

Upvotes: 0

Views: 2450

Answers (1)

Sunny
Sunny

Reputation: 4809

Same as you did with the salesCustomerName but you will need to convert into integer and double and add them.

salesQuantity.Add(Convert.ToInt32(strQuantity));

Similarly for item price, convert to double and add it.

Upvotes: 1

Related Questions