String Basics

Strings and Chars

  • A char is a single 'character'.

  • A string is essentially an array of char.

    • Both of the following data structures practically have the same properties, and the two WriteLine() will print b.

char[] chars = { 'a', 'b', 'c', };
string str = "abc";

Console.WriteLine(chars[1]);
Console.WriteLine(str[1]);

Properties of Strings

Length

string str = "This is a string";
int len = str.Length;
// len will be 16

Null Check

  • Often a string needs to be checked for null or Empty.

  • Following methods facilitates this.

Last updated