C
Join ServerC#
help
Delegate add or equal to?
00x3F10/24/2022
public delegate bool InBehalfOf(string someText);
public class Test : MonoBehaviour
{
internal static InBehalfOf inBehalfOfHandler;
void Update()
{
print(inBehalfOfHandler?.Invoke("It works"));
}
}
I have above class with a delegate declaration, somewhere earlier from different class during the runtime I call below script multiple times per second:Test.inBehalfOfHandler = Test.DoesContainVowel;
What I noticed each time I put "equal to" it seems like it's adding methods to this delegate (I expected this line to do nothing if it's being called over again, like saying int x=5
over again will not change anything)Test.inBehalfOfHandler += Test.DoesContainVowel;
this also behaves weird when called multiple times, what does operators =
and +=
do for delegates? 
00x3F10/24/2022
Okay, let's say I added hundreds of the same method to a delegate then I use
=
operator, so it sets back my delegate to have only one method?00x3F10/24/2022
Test is a class, DoesContainVowel is a boolean method in that class

00x3F10/24/2022
Test.inBehalfOfHandler
is a delegate
YYawnder10/24/2022
You know it takes about 5mins to test that, and you'd get a definitive answer right?
00x3F10/24/2022
This is what I was doing before I decided to post a question on this server. Actually @Retax you were right "perhaps there's somewhere else in your code where DoesContainWheel gets more methods somehow" my code is a mess, pressing a button switches between
and
but I just realized each time I press that button I'm instantiating objects of the Test class (so I keep creating new delegates for each)
That was the issue, my distraction, therefore I was unable to understand why 
Test.inBehalfOfHandler = Test.DoesContainDigit;
and
Test.inBehalfOfHandler = Test.DoesContainVowel;
but I just realized each time I press that button I'm instantiating objects of the Test class (so I keep creating new delegates for each)

=
and +=
behaves weird when I press the button during runtime 😄 sorry for that and thanks @Retax a lot! 