Search⌘ K
AI Features

Working with Variables: Strings

Explore how to work with string variables in C#. Understand different ways to store text, such as literal, verbatim, raw, and interpolated strings. Learn proper naming conventions, escaping techniques, and how new C# features improve text handling for clearer and more efficient code.

All applications process data. Data comes in, data is processed, and then data goes out. Data usually comes into our program from files, databases, or user input, and it can be put temporarily into variables that will be stored in the memory of the running program. When the program ends, the data in memory is lost. Data is usually output to files, databases, the screen, or a printer. When using variables, we should think about the following:

  • How much space does the variable take in the memory?

  • How fast can it be processed?

Application process data
Application process data

We control this by picking an appropriate type. We can think of simple common types such as int and double as different-sized storage boxes, where a smaller container would take less memory but may need to be faster at processing. For example, adding 16-bit numbers might take longer than adding 64-bit numbers on a 64-bit operating system. Some of these boxes may be stacked close by, and some may be thrown into a big heap further away.

Naming things and assigning values

There are naming conventions for things, and it is good practice to ...