0
0
C Sharp (C#)programming~30 mins

Zip operation in C Sharp (C#) - Mini Project: Build & Apply

Choose your learning style9 modes available
Zip Operation in C#
📖 Scenario: You work in a small store. You have two lists: one with product names and one with their prices. You want to combine these lists to see each product with its price.
🎯 Goal: Build a program that uses the Zip operation to pair each product with its price and print the pairs.
📋 What You'll Learn
Create two lists: one called products with exact values "Apple", "Banana", "Cherry"
Create another list called prices with exact values 1.2, 0.5, 2.0
Use a variable called productPrices to store the zipped pairs
Use a foreach loop with variables product and price to iterate over productPrices
Print each product and price in the format: "Apple: $1.2"
💡 Why This Matters
🌍 Real World
Stores and shops often have separate lists for products and prices. Combining them helps show clear price tags or receipts.
💼 Career
Knowing how to combine related data from different lists is useful in many programming jobs, especially in data processing and user interface development.
Progress0 / 4 steps
1
Create the product and price lists
Create a list of strings called products with these exact values: "Apple", "Banana", "Cherry". Also create a list of doubles called prices with these exact values: 1.2, 0.5, 2.0.
C Sharp (C#)
Need a hint?

Use List<string> for products and List<double> for prices. Initialize them with the exact values.

2
Create the zipped pairs
Create a variable called productPrices that uses products.Zip(prices, (product, price) => (product, price)) to combine the two lists into pairs.
C Sharp (C#)
Need a hint?

Use var productPrices = products.Zip(prices, (product, price) => (product, price)); to combine the lists.

3
Loop through the zipped pairs
Use a foreach loop with variables product and price to iterate over productPrices.
C Sharp (C#)
Need a hint?

Use foreach (var (product, price) in productPrices) to loop through the pairs.

4
Print each product with its price
Inside the foreach loop, write Console.WriteLine($"{product}: ${price}"); to print each product and its price.
C Sharp (C#)
Need a hint?

Use Console.WriteLine($"{product}: ${price}"); inside the loop to print each pair.