Strings

There is often the necessity to store some text values. You can achieve this goal using the String built-in reference type from the System namespace, which is also available using the string keyword. The string type is a sequence of Unicode characters. It can have zero chars, one or more chars, or the string variable can be set to null.

You can perform various operations on string objects, such as concatenation or accessing a particular char using the [] operator, as shown as follows:

string firstName = "Marcin", lastName = "Jamro"; 
int year = 1988; 
string note = firstName + " " + lastName.ToUpper()  
   + " was born in " + year; 
string initials = firstName[0] + "." + lastName[0] + "."; 

At the beginning, the firstName variable is declared, ...

Get C# Data Structures and Algorithms now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.