At the moment i have this class
public class Currency
{
private int _Amount;
public Currency(){... }
public Currency(int amount){_Amount = amount;}
public override string ToString()
{
return _Amount + " Gold.";
}
}
I want this class to have all the functionality of an integer so i can do things like this
Currency curr = new Currency();
Currency curr2 = new Currency(100);
curr = 50;
curr += 50;
curr += curr2;
i found kinda of what i needed here : Integer c++ wrapper but this is for C++. Can someone tell me how i do this in C#?
public operator Currency() { return _Amount; }
Doesn't work, nor adding implicit/explicit anywhere.
See implicit (C# Reference) for more info. The second thing you want to check, is operator overloading.