Gibt es einen "reinen Linq" -Scharakter, um eine Abkürzung von zwei Buchstaben in der Stadt zu erstellen?
Posted: 02 May 2025, 07:47
Mein aktueller Code ist dies. Aber ich würde gerne mehr linq -zentrische Muster für solche Dinge lernen < /p>
Code: Select all
string city, cityAbbr;
city = "SANTA FE";
cityAbbr = city.IndexOf(' ') == -1 ? city.Substring(0,2) : new string(city.Split(' ').Select(s => s[0]).ToArray());
// SF
city = "CHICAGO";
cityAbbr = city.IndexOf(' ') == -1 ? city.Substring(0,2) : new string(city.Split(' ').Select(s => s[0]).ToArray());
// CI