简体   繁体   English

非静态字段需要对象引用

[英]object reference is required for the non-static field

What am I doing wrong here? 我在这里做错了什么?

return listBoxKeywords.Items[rnd.Next(0, listBoxKeywords.Items.Count)].ToString();

I get the following error: 我收到以下错误:

Error 1 An object reference is required for the non-static field, method, or property 错误1非静态字段,方法或属性需要对象引用

This error means that the function returning the random item is static. 此错误意味着返回随机项目的函数是静态的。

Either remove the static keyword from the method declaration (and thus make it part of the existing instance), or pass the list box as parameter to the function when calling it. 从方法声明中删除static关键字(从而使其成为现有实例的一部分),或者在调用它时将列表框作为参数传递给函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM