There are at least two other ways you could return a pair of strings.
1. Return one (or both) of them as an
out
parameter. Here, I'm returning both.
public void ReturnIp(string domainName, out string domainIP, out string status)
{
....
}
2. You could define a
struct
or
class
to carry the pair of strings as a single value, and return that an instance of that type (note that I'm including the domain name in the class, so that the name and IP address are always closely associated):
class DomainInfo
{
public string DomainName { get; set; }
public string DomainIp { get; set; }
public string Status { get; set; }
}
...
public DomainInfo ReturnIp(string domainName)
{
...
return new DomainInfo { DomainName = domainName, DomainIp = ..., Status = ... };
}
Your method of concatenating the two strings certainly works, but would be considered by many programmers to be bad form as it combines two distinct values into a single entity.
Please note - unless the status value you want to return is truly a text value, you might find the use of an
enum
to encode the set of possible status values is clearer (and will be definitely more reliable since it doesn't rely on text parsing / comparison to interpret).