+ 2

C#: Для нестатического поля, метода или свойства "..." требуется ссылка на объект

Часто с этим сталкиваюсь. Я понимаю, что можно все сделать static и не париться, но каков другой вариант?

16th Aug 2019, 10:46 AM
Dead Lord
Dead Lord - avatar
2 Respuestas
+ 2
Good question : I used google translate C #: A non-static field, method or property "..." requires an object reference I often come across this. I understand that you can do everything static and not take a steam bath, but what is another option? ( not sure what that steam bath is doing there) I made some code, hopes this answers your question https://code.sololearn.com/c4csrTK8A3eV Really it is personal preference. You can do the "Add" in a static class and also in a non-static class. Sometimes you do not have control of the code and you need to make you methods static because the class is static. Almost every thing I do is bound to a object. I use static only for helper-classes that hold some usefull method. In this case I would go for the static version.
16th Aug 2019, 8:56 PM
sneeze
sneeze - avatar
+ 1
sneeze "steam bath" is like "hakuna matata", like "don't worry". :) I'll watch your cod tomorrow, from PC. Thank you a lot my friend :)🤘
16th Aug 2019, 10:49 PM
Dead Lord
Dead Lord - avatar