codescracker


c#

C# Constants



« Previous Tutorial Next Tutorial »


Constants are fixed values given to a variable, that our program may not alter during the program execution.

Integer Constants in C#

An integer constant can be a decimal, octal, or hexadecimal constant. Here are the prefix that specifies the base:

Here are the list of some legal integer constants C#:

214	// decimal integer constant
0xFeeL	// hexadecimal integer constant
0324	// octal integer constant

Floating-point Constants in C#

A floating-point constants in C# consists of the following parts:

Here are the list of some legal floating-point constants in C#:

3.14159
314159E-5L

Character Constants in C#

Character constants are enclosed in single quotes like 'a', 'b', 'c', 'm', etc. There are some characters in C#, preceded by a backslash. They have special meaning like '\n' for newline, '\t' for tab, etc. Here the following table lists some escape sequence codes in C#:

Escape Sequence Code Output
\\ \
\? ?
\' '
\" "
\t Horizontal tab
\v Vertical tab
\n Newline
\r Carriage return
\a Alert
\f Form feed
\b Backspace
\ooo Octal number of 1 to 3 digits
\xhh . . . Hexadecimal number of one/more digit(s)

Here is an example showing some escape sequence code in C#

/* C# Constants - Example Program */
		
using System;
namespace EscapeSequenceChars
{
   class Escapeclass
   {
      static void Main(string[] args)
      {
         Console.WriteLine("Hello\n\tWorld\n\nI\tam\t\"C#\".");
         Console.ReadLine();
      }
   }
}

When the above code is compiled and executed, it would produce the following output:

Hello
	World

I	am	"C#"

String Constants in C#

String constants are enclose in double quotes. Here are the list of some legal string constants in C# programming:

"Hello World"
"hello"
"i"
"this is C# constants tutorial"
"you are learning C# constants at codescracker.com"

« Previous Tutorial Next Tutorial »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test