简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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