Difference between revisions of "Character"

esse quam videri
Jump to: navigation, search
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
=Definition=
 
=Definition=
A Character (or Char as used in code) is a 16-bit, Unicode character.
+
A Character (or Char as used in code) is a 16-bit, Unicode character. A character can be a letter, number or symbol.
  
 
=Relevance=
 
=Relevance=
Characters are used to make up strings.
+
Characters are used to make up strings. There may be times when separating strings into the characters that make them up will be useful.
  
 
=Explanation=
 
=Explanation=
If you think of the word "Car", it is comprised of 3 characters: 'C', 'a' and 'r'.
+
If you think of the word "Car", it is comprised of 3 characters: 'C', 'a' and 'r'.  
 
Note that a space is still a character. Thus, the word "Race Car" is comprised of 8 characters: 'R', 'a', 'c', 'e', ' ', 'C', 'a' and 'r'.
 
Note that a space is still a character. Thus, the word "Race Car" is comprised of 8 characters: 'R', 'a', 'c', 'e', ' ', 'C', 'a' and 'r'.
  
Line 12: Line 12:
  
 
=Example=
 
=Example=
 +
<syntaxhighlight lang ="csharp">
 +
char firstInitial = 'J';
 +
char lastInitial = 'D';
 +
char favNumber = '3'; // This is still valid, the 3 will not be used for math but the character data type can hold a single digit as shown.
 +
char favSymbol = '$'; // This is still valid. Even though the dollar sign is a symbol, it is still a character.
  
 +
char badExample = "B"; // This will throw an error because the compiler will expect single quotes (' ') instead of double quotes (" "). Simply change the quotes to fix the error.
 +
char badExample2 = 'b2'; // This will throw an error because a character can only be a single letter/ number. Having two as shown is not allowed.
 +
</syntaxhighlight>
  
=Resources=
 
  
  
== See also ==
 
  
==Notes==
 
  
  
==External Links==
 
  
  

Latest revision as of 15:45, 8 August 2019

Definition

A Character (or Char as used in code) is a 16-bit, Unicode character. A character can be a letter, number or symbol.

Relevance

Characters are used to make up strings. There may be times when separating strings into the characters that make them up will be useful.

Explanation

If you think of the word "Car", it is comprised of 3 characters: 'C', 'a' and 'r'. Note that a space is still a character. Thus, the word "Race Car" is comprised of 8 characters: 'R', 'a', 'c', 'e', ' ', 'C', 'a' and 'r'.

Another note is that while strings use double quotes (" ") to specify a value, characters use single quotes (' ').

Example

char firstInitial = 'J';
char lastInitial = 'D';
char favNumber = '3'; // This is still valid, the 3 will not be used for math but the character data type can hold a single digit as shown.
char favSymbol = '$'; // This is still valid. Even though the dollar sign is a symbol, it is still a character.

char badExample = "B"; // This will throw an error because the compiler will expect single quotes (' ') instead of double quotes (" "). Simply change the quotes to fix the error.
char badExample2 = 'b2'; // This will throw an error because a character can only be a single letter/ number. Having two as shown is not allowed.