char variables can be added together as if they were 'normal' integers. - CSharp Language Basics

CSharp examples for Language Basics:char

Description

char variables can be added together as if they were 'normal' integers.

Demo Code

using System;//  w  ww  .  j  av  a  2  s  .c o  m
public class Characters
{
   public static void Main()
   {
      char firstSymbol;
      char secondSymbol;
      int intFirstSymbol;
      int intSecondSymbol;
      int result;
      firstSymbol = '\u0034';
      secondSymbol = '\u0039';
      Console.WriteLine("firstSymbol as character: " + firstSymbol);
      Console.WriteLine("secondSymbol as character: " + secondSymbol);
      intFirstSymbol = firstSymbol;
      intSecondSymbol = secondSymbol;
      Console.WriteLine("firstSymbol as int: " + intFirstSymbol);
      Console.WriteLine("secondSymbol as int: " + intSecondSymbol);
      result = firstSymbol + secondSymbol;
      Console.WriteLine("Result as int: " + result);
      Console.WriteLine("Result as character: " + (char)result);
   }
}

Result


Related Tutorials