I think performance won't be a big issue here as the concatenation only happens once (2-3 at worse because of multiple threads). Out of the two methods, which one would you prefer, in terms of readability and performance? Is there any better way to accomplish the task of calculating desired string:uaInfo?
public static string GetUserAgentInfo()
{
if (_uaInfo == null)
{
string carrier = DeviceNetworkInformation.CellularMobileOperator ?? "(No Network)";
var sb = new StringBuilder();
sb.Append("device-type=mobile");
sb.Append(";os=Windows Phone");
sb.Append(";os-version=" + Environment.OSVersion.Version);
sb.Append(";app-name:" + GetAppName());
sb.Append(";app-version=" + GetVersion());
sb.Append(";carrier=" + HttpUtility.UrlEncode(carrier));
sb.Append(";locale=" + Locale);
_uaInfo = sb.ToString();
}
return _uaInfo;
}
public static String GetUserAgentInfoOld()
{
if (_uaInfo == null)
{
string carrier = DeviceNetworkInformation.CellularMobileOperator ?? "(No Network)";
string temp = "";
temp += String.Format("{0}={1};", "device-type", "mobile");
temp += String.Format("{0}={1};", "os", "Windows Phone");
temp += String.Format("{0}={1};", "os-version", Environment.OSVersion.Version);
temp += String.Format("{0}={1};", "app-name", GetAppName());
temp += String.Format("{0}={1};", "app-version", GetVersion());
temp += String.Format("{0}={1};", "carrier", HttpUtility.UrlEncode(carrier));
temp += String.Format("{0}={1}", "locale", Locale);
_uaInfo = temp;
}
return _uaInfo;
}