Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Zeichen | Umgang mit Datentypen
C# Grundlagen

bookZeichen

The keyword char represents a single character. A character value is always enclosed in single quotes (').

main.cs

main.cs

copy
12345678910111213141516
using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { char letter1 = 'a'; char letter2 = 'b'; Console.WriteLine(letter1); // Output: a Console.WriteLine(letter2); // Output: b } } }

Every character has a corresponding number in the ASCII table, which is a system used by computers to represent text. For example, a is 97 and b is 98. You can see the full table here. Arithmetic operations on characters use these numbers. For example:

main.cs

main.cs

copy
123456789101112131415
using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { char var1 = 'a'; char var2 = 'b'; Console.WriteLine(var1 + var2); // Output: 195 } } }

The above code outputs 195 because the sum of the ASCII values of a and b is 195.

The digits from 0 to 9 can also be represented as characters by enclosing them in single quotes:

char val = '7';

However, digits represented as characters are NOT the same as integers.

Note

Summing letters using ASCII values can be useful in creating simple hash functions. These functions can be used for data integrity checks or distributing data across storage systems. By summing the ASCII values of characters in a string, you can generate a unique numerical representation of that string.

question mark

Which one of these is a char value?

Select the correct answer

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 2. Kapitel 5

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

bookZeichen

Swipe um das Menü anzuzeigen

The keyword char represents a single character. A character value is always enclosed in single quotes (').

main.cs

main.cs

copy
12345678910111213141516
using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { char letter1 = 'a'; char letter2 = 'b'; Console.WriteLine(letter1); // Output: a Console.WriteLine(letter2); // Output: b } } }

Every character has a corresponding number in the ASCII table, which is a system used by computers to represent text. For example, a is 97 and b is 98. You can see the full table here. Arithmetic operations on characters use these numbers. For example:

main.cs

main.cs

copy
123456789101112131415
using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { char var1 = 'a'; char var2 = 'b'; Console.WriteLine(var1 + var2); // Output: 195 } } }

The above code outputs 195 because the sum of the ASCII values of a and b is 195.

The digits from 0 to 9 can also be represented as characters by enclosing them in single quotes:

char val = '7';

However, digits represented as characters are NOT the same as integers.

Note

Summing letters using ASCII values can be useful in creating simple hash functions. These functions can be used for data integrity checks or distributing data across storage systems. By summing the ASCII values of characters in a string, you can generate a unique numerical representation of that string.

question mark

Which one of these is a char value?

Select the correct answer

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 2. Kapitel 5
some-alt