"不包含一个定义......没有扩展名的方法.."错误 [英] "does not contain a definition...and no extension method.." error

查看:172
本文介绍了"不包含一个定义......没有扩展名的方法.."错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下错误信息:

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

我检查那么对于这一点,我发现<一href="http://stackoverflow.com/questions/5706594/system-web-httppostedfilebase-does-not-contain-a-definition-for-hasfile-and-n">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;
}

这篇关于&QUOT;不包含一个定义......没有扩展名的方法..&QUOT;错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆