Possible class function in C# -
i have class created:
public class character { public string name, owner; public int str, con, dex, int, wis, cha, ac, speed, maxhp, currhp, ap, sv, surges; }
as can see, it's simple class @ moment. question is, there way create class inside when call function can have math equation returned?
example:
character c = new character(); c.name = "goofy"; c.owner = "me"; c.str = 15; messagebox.show(c.str.mod);
the output window "7" (mod is: math.floor(str / 2);)
i have been trying search both , google time , have yet figure out. may searching wrong phrases or might not possible.
thanks
only way can think extension methods
class program { static void main(string[] args) { character c = new character(); c.name = "goofy"; c.owner = "me"; c.str = 15; console.writeline(c.str.mod()); console.read(); } } public class character { public string name, owner; public int str, con, dex, int, wis, cha, ac, speed, maxhp, currhp, ap, sv, surges; } public static class ext { public static int mod(this int value) { return (int)math.floor(value / 2.0); } }
Comments
Post a Comment