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

发布于 2024-12-01 08:20:59 字数 1104 浏览 0 评论 0原文

我收到以下错误消息:

'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 语句,但我几乎肯定我拥有我需要的所有 using 语句。

以下是一些产生错误的代码:

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

抱歉,如果我对变量的重命名以及诸如此类的内容令人困惑。如果它不可读,或者太难理解,或者其他信息与解决方案相关,请告诉我。谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

×眷恋的温暖 2024-12-08 08:20:59

问题出在这部分:cart.biffcart 的类型为 Dictionary,而不是 SpoofClass 类型。

我只能猜测你想做什么,但以下代码可以编译:

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

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;
}
抹茶夏天i‖ 2024-12-08 08:20:59

您需要访问给定键的字典值。沿着这些思路。

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

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;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文