"does not contain a definition ... and does not have an extension method .."

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 the SO for this, and I found this question that seemed to have a similar (if not identical) problem like mine. However, I tried the solution provided in the accepted answer, and he still didn't come up with anything. It acts as if I lack a service statement, but I'm pretty sure that I have everything I need.

Here is the error code:

 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 something is not confusing. If it is unreadable or too difficult to follow, or if other information is appropriate for the solution, let me know. Thanks!

+4
source share
2 answers

The problem is this part: cart.biff . cart is of type Dictionary<int, SpoofClass> , and 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; } 
+6
source

You need to access the dictionary value for the given key. Something like that.

 foreach(var item in dbContext.DBView) { foreach(var key in cart.Keys) { cart[key].biff = item.biff; } } 
+4
source

All Articles