Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
CSharpNotesForProfessionals.pdf
Скачиваний:
57
Добавлен:
20.05.2023
Размер:
6.12 Mб
Скачать

s = s.ToLowerInvariant(); // "my string" s = s.ToUpperInvariant(); // "MY STRING"

Note that you can choose to specify a specific Culture when converting to lowercase and uppercase by using the String.ToLower(CultureInfo) and String.ToUpper(CultureInfo) methods accordingly.

Section 11.18: Concatenate an array of strings into a single string

The System.String.Join method allows to concatenate all elements in a string array, using a specified separator between each element:

string[] words = {"One", "Two", "Three", "Four"};

string singleString = String.Join(",", words); // singleString = "One,Two,Three,Four"

Section 11.19: String Concatenation

String Concatenation can be done by using the System.String.Concat method, or (much easier) using the + operator:

string first = "Hello "; string second = "World";

string concat = first + second; // concat = "Hello World" concat = String.Concat(first, second); // concat = "Hello World"

In C# 6 this can be done as follows:

string concat = $"{first},{second}";

GoalKicker.com – C# Notes for Professionals

61