5
I’m building a dictionary of the following kind: <string, delegate>
, that will access a method belonging to an object of the following class:
class Example{
public int Power { get; set; }
public int Defense { get; set; }
public void Method(){
Console.WriteLine("Power: " + Power + " Defense: " + Defense);
}
}
As seen, the method depends on the properties of the class object, as it has to access the Power
and the Defense
. If I store the method, through a delegate
in the dictionary and rotate it from a Dicionario["string"]();
will it be able to access the properties of the object to which the method belongs? If so, how?