#20 – Literals

A literal in C# is a representation, in your source code, of a constant value.  You can use literals when assigning a value to a variable, when passing a parameter value to a method, or wherever a variable of the corresponding type is expected.

C# defines six different types of literals:

  • Boolean literal:  true | false
  • Integer literal:  e.g. 12, 24L, 100UL, 0x7DC
  • Real literal:  e.g. 1.0, 2.2F, 4, 6.02E23, 123.45m
  • Character literal:  e.g. ‘a’, ‘Z’, ‘#’, ‘\n’, ‘\”, ‘\\’, ‘\x45′, ‘\x04DA’
  • String literal: e.g. “Sean”, @”Print\nMe”, “Look: \x04DA”, “Look: Ӛ”, “Line 1\nLine 2″
  • Null literal:  null

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

One Response to #20 – Literals

  1. Pingback: #22 – Integer Literals « 2,000 Things You Should Know About C#

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 43 other followers