2017-02-20 39 views
0

這裏是我的字典數據類型:如果能夠拉含列表<>詞典的值

private Dictionary<String, List<PriceAndStandard>> 

PriceAndStandard是一個結構:

struct PriceAndStandard 
{ 
    public double mePrice; 
    public int? meStandard; 
} 

我希望能夠抓住mePrice和meStandard爲每一個項目。

錯誤我recieving

Type of conditional expression cannot be determined because there is no implicit conversion between 'System.Collections.Generic.List<AspDotNetStorefront.showproduct.PriceAndStandard> 

我就能夠抓住的價值,如果它是一個基本的鍵 - 字符串值對:

shaftModelDictionary.Values.ToList(); 

但因爲我有一個列表我真的需要將數據展平以便可以存儲。

工作代碼:

  foreach (string option in product.AvailableClubOptions.ShaftModel) 
      { 
       string shaftModelText = option; 
       if (minPriceForShaftMaterial > 0 && !string.IsNullOrEmpty(option)) 
       { 
        List<PriceAndStandard> Paul = shaftModelDictionary.Keys.ToList(); 
        double priceForShaftModel = shaftModelDictionary.[option]; 
        double priceForSelectedShaftModel = !String.IsNullOrEmpty(shaftModel) ? shaftModelDictionary[shaftModel] : 0; 

更新: 好像有一個與option一個問題,因爲這是一個字符串,在我的字典裏是列出的值不兼容。

更新2:

foreach (string option in product.AvailableClubOptions.ShaftModel) 
        { 
         string shaftModelText = option; 
         if (minPriceForShaftMaterial > 0 && !string.IsNullOrEmpty(option)) 
         { 
          double priceForShaftModel = shaftModelDictionary[option].mePrice; 
          double priceForSelectedShaftModel = !String.IsNullOrEmpty(shaftModel) ? shaftModelDictionary[shaftModel].mePrice : 0m; 
          double priceDelta = 0.0d; 
          double MinimumPrice = Convert.ToDouble(ltOurPrice.InnerText.Replace("$", "")); 

'列表' 中不包含關於 'mePrice' 和沒有擴展方法的定義 'mePrice' 接受型 '列表'

回答

0

嘗試的第一個參數:

double priceForSelectedShaftModel = !String.IsNullOrEmpty(shaftModel) ? shaftModelDictionary[shaftModel].first().mePrice : 0d; 

編輯: 我的第一個回答是不正確的,對不起。您的字典中的值是列表。因此,當您檢索一個值(它是PriceAndStandard對象列表)時,您需要使用該列表或在列表中找到要處理的特定PriceAndStandard對象。在示例中,我使用first()方法來查找列表中的第一個對象。您可能需要閱讀LINQ並使用where()方法或類似的東西。

我不確定你想要完成什麼......你確定你想讓你的字典中的值爲列表嗎?沒有什麼不對,除了有點不尋常。也許你在想這個嗎?:

private Dictionary<String, PriceAndStandard> 

另外0m是十進制,0d是雙精度。我的錯。

+0

第一條紅色swigely線下雙價priceForShaftModel = shaftModelDictionary [選項] – user1869407

+0

請參閱我的編輯 - 在最後添加「m」。 – Sam

+0

檢查更新2. mePrice在我的IDE中有一個下劃線的swigley,它們發生在這兩個地方 – user1869407

相關問題