简体   繁体   中英

C# How do I translate this foreach loop to a for loop

The statement below returns a price for each item in results. How do I create an array for the returned prices so I can add, subtract, etc. the prices?

foreach (SearchItem item in result.item)
{
   Console.WriteLine("Item Converted Price: " + 
                     item.sellingStatus.convertedCurrentPrice.ToString("0.00", 
                     CultureInfo.InvariantCulture));
}

Using Linq expression:

result.item.Select(x => item.sellingStatus.convertedCurrentPrice.ToString("0.00", CultureInfo.InvariantCulture)).ToArray()

But this would create an array of strings, not numerical values.

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