“不包含定义......并且没有扩展方法......”错误
我收到以下错误消息:
'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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题出在这部分:
cart.biff
。cart
的类型为Dictionary
,而不是SpoofClass
类型。我只能猜测你想做什么,但以下代码可以编译:
The problem is this part:
cart.biff
.cart
is of typeDictionary<int, SpoofClass>
, not of typeSpoofClass
.I can only guess what you are trying to do, but the following code compiles:
您需要访问给定键的字典值。沿着这些思路。
You need to access the Value of the Dictionary for a given key. Something along these lines.