
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Literals in C#
The fixed values are called literals. The constants refer to fixed values that the program may not alter during its execution.
Constants can be of any of the basic data types like an integer constant, a floating constant, a character constant, or a string literal. There are also enumeration constants as well.
Let us learn about integer, float, and string literals in C# −
Integer Literals
An integer literal can be a decimal, or hexadecimal constant. A prefix specifies the base or radix: 0x or 0X for hexadecimal, and there is no prefix id for decimal.
Here are some example of Integer Literals −
20 // int 30u // unsigned int 30l // long
Float Literals
A floating-point literal has an integer part, a decimal point, a fractional part, and an exponent part. You can represent floating point literals either in decimal form or exponential form.
Here are some examples of Float Literals −
2.64734 314159E-5F
String Literals
String literals or constants are enclosed in double quotes "" or with @"". A string contains characters that are similar to character literals: plain characters, escape sequences, and universal characters.
Here are some examples of String Literals −
Hello, World" "Welcome, \
- Related Articles
- Integer literals vs Floating point literals in C#
- Literals in Java programming
- Boolean Literals in Java
- Compound Literals in C
- Octal literals in C
- What is the difference between character literals and string literals in Java?
- User Defined Literals in C++
- What are literals in Java?
- What are literals in C++?
- Formatted string literals in C#
- Tagged Template Literals in JavaScript
- What are Literals in Python?
- Perl Special Literals
- What are Boolean literals in Java?
- What are Boolean Literals in C++?
