Note that in this case, the integer version of your function has to be converted to a string anyway for inclusion in the list. So if your entire problem is really as stated, you only need the string version of your function and can just call it like this:
int SomeValue = 42;
string SomeName= "The Answer to Life, the Universe, and Everything";
Add(SomeName, SomeValue.ToString());
But if you are asking about a more general problem, you can just use the object
type, like this:
public void Add(string key, object value)
{
string valueString = value.ToString();
if (!string.IsNullOrEmpty(valueString))
{
Attributes.Add(key + "=\"" + valueString + "\" ");
}
}
Note that this version has to create an extra variable and call your argument's .ToString()
method, neither of which are needed for the string-only version of the function. This extra work is minuscule, and will hardly drive performance for your app; but it's not free either. However, the nice thing here is that if you call it with a string argument overload-resolution should call the (better) string-version of the function. So you would still want to define two methods, but as you discover more types you need to worry about you don't have to keep adding methods. It stops at two.