Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"does not contain a definition...and no extension method.." error

I have the following error message:

'System.Collections.Generic.Dictionary<int,SpoofClass>' does not
contain a definition for 'biff' and no extension method 'biff'
accepting a first argument of type
'System.Collections.Generic.Dictionary<int,SpoofClass>' could be found
(are you missing a using directive or an assembly reference?)

I checked SO for this and I found this question which seemed to have a similar (if not identical) problem as I am having. However, I tried the solution provided in the accepted answer and it still isn't coming up with anything. It's acting like I am missing a using statement, but I am almost positive I have all the using's I need.

Here is some of the code that is producing the errors:

using locationOfSpoofClass;
...

Dictionary<int, SpoofClass> cart = new Dictionary<int, SpoofClass>();
foreach (var item in dbContext.DBView)
{
    cart.biff = item.biff;
    ...
}

SpoofClass file:

namespace locationOfSpoofClass
{
    public class SpoofClass
    {
        public int biff { get; set; }
        ...
    }
}

Sorry if my renaming of variables and whatnot is confusing. If it is unreadable, or too hard to follow, or if other information is pertinent to the solution, please let me know. Thanks!

like image 299
AmbiguousX Avatar asked Feb 24 '23 04:02

AmbiguousX


1 Answers

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;
}
like image 67
Daniel Hilgarth Avatar answered Mar 09 '23 05:03

Daniel Hilgarth