I have a method that needs to return different data types based on a search. I'm considering two approaches, since I'm new to C# I don't know which is best, so please help me make my mind.
the first approach is to overload the method like this:
public int Get(string name){
//...
return intValue;
}
public double Get(string name){
//...
return doubleValue;
}
public string Get(string name){
//...
return stringValue;
}
the second approach is to have different methods for each data type like this:
public int GetInt(string name){
//...
return intValue;
}
public double GetDouble(string name){
//...
return doubleValue;
}
public string GetString(string name){
//...
return stringValue;
}
which one is the safest for C# considering this code will be published from a DLL?