Possible class function in C#

I have a 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 you can see, it's a very simple class at the moment. My question is, is there a way to create another class inside this so when I call my function I can have a math equation returned?

Example:

character c = new character();
c.Name = "Goofy";
c.Owner = "Me";
c.Str = 15;
MessageBox.Show(c.Str.Mod);

The output to the window would be "7" (Mod is: Math.Floor(Str / 2);)

I have been trying to search both SO and Google for some time and have yet to figure this out. I may be searching for the wrong phrases or this might not even be possible.

Thanks

Answers


only way that I can quickly think is 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);
    }
}

Need Your Help

C#: ICollection with Interface as Type like ICollection<ILocalized>

c# signature icollection

Im working with EntitFramework which generates my Entity classes:

Check if all values in single array exist in string

ruby arrays string

For all vowels in a string, I'm trying to print the amount of the vowels. If I push every instance of a vowel to a new array, then the length of the array + 1 would be the answer. I don't know if m...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.