“不包含定义......并且没有扩展方法..”错误

时间:2022-04-29 16:56:48

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.

我检查了SO,我发现这个问题似乎与我有类似(如果不是完全相同)的问题。但是,我尝试了接受的答案中提供的解决方案,但仍然没有提出任何建议。它表现得像我错过了一个使用声明,但我几乎是积极的,我有我需要的所有使用。

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!

对不起,如果我重命名变量等等是令人困惑的。如果它不可读或难以理解,或者其他信息与解决方案相关,请告诉我。谢谢!

2 个解决方案

#1


6  

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

问题在于这一部分:cart.biff。 cart的类型为Dictionary ,而不是SpoofClass类型。 ,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;
}

#2


4  

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;
    }
}

#1


6  

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

问题在于这一部分:cart.biff。 cart的类型为Dictionary ,而不是SpoofClass类型。 ,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;
}

#2


4  

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;
    }
}