Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
String | Dealing with Data Types
C# Basics
course content

Conteúdo do Curso

C# Basics

C# Basics

1. Getting Started
2. Dealing with Data Types
3. Control Structures
4. Loops
5. Arrays
6. Methods

bookString

A string is a sequence of characters. Strings are used for storing textual data.

cs

main

copy
1234567891011121314
using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { string text = "Hello, World!"; Console.WriteLine(text); // Output: Hello, World! } } }

String data (text) is always enclosed in double quotation marks (").

We of course cannot perform arithmetic operations on strings however we can use the plus (+) operator to join two strings. The process of joining strings using the plus operator is called string concatenation.

cs

main

copy
123456789101112131415
using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { string partOne = "The first sentence. "; string partTwo = "The second sentence."; string combined = partOne + partTwo; Console.WriteLine(combined); // Output: The first sentence. The second sentence. } } }

We can use the new line character (\n) to represent a new line in string data.

For-example:

cs

main

copy
12345678910111213
using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { string text = "The first line.\nThe second line."; Console.WriteLine(text); } } }

When the \n character is encountered, the text automatically shifts to a new line. We can use multiple newline characters to skip multiple lines:

cs

main

copy
12345678910111213
using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { string text = "The first line.\n\n\nThe second line.\nThe third line."; Console.WriteLine(text); } } }
What will be the output of the following code?

What will be the output of the following code?

Selecione a resposta correta

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 6
some-alt