"不包含一个定义......没有扩展名的方法.."错误扩展名、不包含、定义、错误

2023-09-03 15:06:12 作者:谢谢你给过的砰然心动

我有以下错误信息:

'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?)

我检查那么对于这一点,我发现this问题这似乎也有类似的(如果不相同)的问题,因为我有。不过,我想在接受答案提供的解决方案,它仍然没有想出什么。它的作用就像我缺少一个using语句,但我几乎可以肯定我所有的用的,我需要。

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.

下面是一些code,它是生产中的错误:

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文件:

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!

推荐答案

现在的问题是这一部分: cart.biff 的类型是词典&LT; INT,SpoofClass&GT; ,而不是类型的 SpoofClass

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

我只能猜测你正在尝试做的,但下面的code编译:

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