0
How can I pass self parameters to a C# methods?
Example: I have two instances of a class, each one with atk, def, hp etc... I wanna do the python equivalent monster 1.attack(monster2) but I don't know how to pass self.atk where self is monster 1. I can do it with Monster1.attack(Monster Monster1, Monster Monster2) but I think is not as useful as in Python. Any suggestion?
4 ответов
+ 2
In C# and in most OOP languages you don't have to add a "self" parameter that is the object itself, they do it for you which is usually called "this" e.g.
https://code.sololearn.com/ceZs0vcFUHsf/?ref=app
0
yr saying Monster1.attack(Monster monster2) and then this.hp refers to monster 1 hps?
0
Stefano Marzo you don't have to pass monster1 at all, C# does it for you in the form of "this"
0
really good example. Thanks. I'll work on it and let you know, posting my code. Again really useful.