Chciałbym zapisać poniższy kod w jednej linijce. Jakie będzie poprawne użycie kolejności funkcji (o ile jest to możliwe)?
tekst= tekst.Trim();
tekst= tekst.Remove(tekst.Length - 1);
Chciałbym zapisać poniższy kod w jednej linijce. Jakie będzie poprawne użycie kolejności funkcji (o ile jest to możliwe)?
tekst= tekst.Trim();
tekst= tekst.Remove(tekst.Length - 1);
tekst = tekst.Trim().Remove(tekst.Trim().Length -1);
??
Chyba lepiej zrobić to w dwóch linijkach.
string text = "abcde".RemoveLastCharacter();
A gdzieś jeszcze:
static class StringExtensions
{
public static string RemoveLastCharacter(this string text)
{
var result = text.Trim();
result = text.Remove(text.Length - 1);
return result;
}
}