mam:String.Format metodę rozszerzenia
public static string Format(this string text, params object[] args)
{
return string.Format(text, args);
}
Więc mogę zrobić:
"blablabla {0}".Format(variable1);
Czy to dobry/zły? Czy może stać się jeszcze krótszy? Chcę mieć ciągi budować bezproblemowo, jak pisanie tekstu bez obawy przed lub po parametrów i rzeczy:
// bad
return "date: " + DateTime.Now.ToString("dd.MM.yyyy") + "\ntime: " + DateTime.Now.ToString("mm:HH:ss") + "\nuser: " + _user + " (" + _status + ")";
// better, but you have to deal with order of {0}...{n} and order of parameters
return string.Format("date: {0}\ntime: {1}\user: {2} ({3})", ...);
// ideal
return "date: {DateTime.Now{dd:MM:yyyy}}\ntime: {...}\nuser: {_user} ({_status})";
Uważam, że oczekiwany wynik tego pomysłu jest bardzo mylący. – Steve
"Czy to jest dobre/złe?": Pytasz o opinie, które nie są tutaj tematem [SO]. – Richard
@Richard, to tylko jedno z kilku pytań, które zadałem = P – Sinatr