Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Cadena | Manejo de Tipos de Datos
Conceptos básicos de C#

book
Cadena

Una string es una secuencia de caracteres. Las cadenas se utilizan para almacenar datos textuales.

cs

main

copy
using System;

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

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

Los datos de cadena (texto) siempre están encerrados entre comillas dobles (").

Por supuesto, no podemos realizar operaciones aritméticas en cadenas, sin embargo, podemos usar el operador más (+) para unir dos cadenas. El proceso de unir cadenas usando el operador más se llama concatenación de cadenas.

cs

main

copy
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.
}
}
}
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
using System;

namespace ConsoleApp
{
internal class Program
{
static void Main(string[] args)
{
string text = "The first line.\nThe second line.";
Console.WriteLine(text);
}
}
}
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
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);
}
}
}
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); } } }
question mark

What will be the output of the following code?

Console.WriteLine("One" + " , " + "Two");

Select the correct answer

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 6

Pregunte a AI

expand
ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

some-alt