“does not contain a definition…and no extension method..” error

前端 未结 2 1455
予麋鹿
予麋鹿 2021-01-06 08:09

I have the following error message:

\'System.Collections.Generic.Dictionary\' does not
contain a definition for \'biff\' and no extensi         


        
相关标签:
2条回答
  • 2021-01-06 08:30

    You need to access the Value of the Dictionary for a given key. Something along these lines.

    foreach(var item in dbContext.DBView)
    {
        foreach(var key in cart.Keys)
        {
            cart[key].biff = item.biff;
        }
    }
    
    0 讨论(0)
  • 2021-01-06 08:48

    The problem is this part: cart.biff. cart is of type Dictionary<int, SpoofClass>, not of type SpoofClass.

    I can only guess what you are trying to do, but the following code compiles:

    Dictionary<int, SpoofClass> cart = new Dictionary<int, SpoofClass>();
    int i=0;
    foreach (var item in dbContext.DBView)
    {
        cart.Add(i, new SpoofClass { biff = item.biff });
        ++i;
    }
    
    0 讨论(0)
提交回复
热议问题