Getting started with C# LanguageVerbatim StringsOperatorsExtension MethodsCollection InitializersString InterpolationC# 6.0 FeaturesConstructors and FinalizersKeywordsGenericsReflectionInheritanceNull-Coalescing OperatorUsing StatementString Escape SequencesException HandlingNull-conditional OperatorsBuilt-in TypesLambda expressionsAsync-AwaitPropertiesThreadingUsing DirectiveMethodsYield KeywordEventsLINQ QueriesCommon String OperationsExpression TreesOverload ResolutionString.Formatnameof OperatorUnsafe Code in .NETInitializing PropertiesBindingList<T>ILGeneratorObject initializersXML Documentation CommentsPreprocessor directivesDynamic typeAnonymous typesStructsTuplesEnumAccess ModifiersTask Parallel LibraryAttributesGuidSingleton ImplementationDelegatesNullable typesGarbage Collector in .NetNetworkingArraysEquality OperatorLock StatementAction FiltersXmlDocument and the System.Xml namespaceDateTime MethodsBackgroundWorkerPolymorphismStatic ClassesIndexerIDisposable interfaceAliases of built-in typesImmutabilityXDocument and the System.Xml.Linq namespaceC# 7.0 FeaturesPerforming HTTP requestsGenerating Random Numbers in C#LoopingNamed ArgumentsDiagnosticsInterfacesIEnumerableNaming ConventionsAn overview of c# collectionsChecked and UncheckedRecursionFunctional ProgrammingLiteralsCastingNullReferenceExceptionFunc delegatesLINQ to XMLHash FunctionsHandling FormatException when converting string to other typesCryptography (System.Security.Cryptography)INotifyPropertyChanged interfaceValue type vs Reference typeC# 4.0 FeaturesIQueryable interfaceTask Parallel Library (TPL) Dataflow ConstructsStreamRuntime CompileConditional StatementsInteroperabilityOverflowEquals and GetHashCodeType ConversionParallel LINQ (PLINQ)String ManipulationString ConcatenatePartial class and methodsStopwatchesRegex ParsingC# ScriptC# 3.0 FeaturesAsync/await, Backgroundworker, Task and Thread ExamplesTimersFunction with multiple return valuesBinary SerializationMaking a variable thread safeIComparableCode ContractsIteratorsAssemblyInfo.cs ExamplesFile and Stream I/OCode Contracts and AssertionsCachingC# 5.0 FeaturesImplementing Flyweight Design PatternStringBuilderImplementing Decorator Design PatternAccessing DatabasesT4 Code GenerationMicrosoft.Exchange.WebServices.NET Compiler Platform (Roslyn)Data AnnotationUsing SQLite in C#System.Management.AutomationFileSystemWatcherSystem.DirectoryServices.Protocols.LdapConnectionNamed and Optional ArgumentsComments and regionsC# Authentication handlerPointers & Unsafe CodePointersHow to use C# Structs to create a Union type (Similar to C Unions)BigIntegerDependency InjectionReactive Extensions (Rx)Creational Design PatternsCreating a Console Application using a Plain-Text Editor and the C# Compiler (csc.exe)Reading and writing .zip filesGeneric Lambda Query BuilderImport Google ContactsLambda ExpressionsCLSCompliantAttributeObservableCollection<T>Synchronization Context in Async-AwaitICloneableRead & Understand StacktracesLinq to ObjectsASP.NET IdentityAccess network shared folder with username and passwordAsynchronous SocketStructural Design PatternsO(n) Algorithm for circular rotation of an arrayCreating Own MessageBox in Windows Form ApplicationIncluding Font ResourcesObject Oriented Programming In C#Using json.netGetting Started: Json with C#Windows Communication Foundation

Literals

Other topics

int literals

int literals are defined by simply using integral values within the range of int:

int i = 5;

uint literals

uint literals are defined by using the suffix U or u, or by using an integral values within the range of uint:

uint ui = 5U;

string literals

string literals are defined by wrapping the value with double-quotes ":

string s = "hello, this is a string literal";

String literals may contain escape sequences. See String Escape Sequences

Additionally, C# supports verbatim string literals (See Verbatim Strings). These are defined by wrapping the value with double-quotes ", and prepending it with @. Escape sequences are ignored in verbatim string literals, and all whitespace characters are included:

string s = @"The path is:
C:\Windows\System32";
//The backslashes and newline are included in the string

char literals

char literals are defined by wrapping the value with single-quotes ':

char c = 'h';

Character literals may contain escape sequences. See String Escape Sequences

A character literal must be exactly one character long (after all escape sequences have been evaluated). Empty character literals are not valid. The default character (returned by default(char) or new char()) is '\0', or the NULL character (not to be confused with the null literal and null references).

byte literals

byte type has no literal suffix. Integer literals are implicitly converted from int:

byte b = 127;

sbyte literals

sbyte type has no literal suffix. Integer literals are implicitly converted from int:

sbyte sb = 127;

decimal literals

decimal literals are defined by using the suffix M or m on a real number:

decimal m = 30.5M;

double literals

double literals are defined by using the suffix D or d, or by using a real number:

double d = 30.5D;

float literals

float literals are defined by using the suffix F or f, or by using a real number:

float f = 30.5F;

long literals

long literals are defined by using the suffix L or l, or by using an integral values within the range of long:

long l = 5L;

ulong literal

ulong literals are defined by using the suffix UL, ul, Ul, uL, LU, lu, Lu, or lU, or by using an integral values within the range of ulong:

ulong ul = 5UL;

short literal

short type has no literal. Integer literals are implicitly converted from int:

short s = 127;

ushort literal

ushort type has no literal suffix. Integer literals are implicitly converted from int:

ushort us = 127;

bool literals

bool literals are either true or false;

bool b = true;

Syntax:

  • bool: true or false
  • byte: None, integer literal implicitly converted from int
  • sbyte: None, integer literal implicitly converted from int
  • char: Wrap the value with single-quotes
  • decimal: M or m
  • double: D, d, or a real number
  • float: F or f
  • int: None, default for integral values within the range of int
  • uint: U, u, or integral values within the range of uint
  • long: L, l, or integral values within the range of long
  • ulong: UL, ul, Ul, uL, LU, lu, Lu, lU, or integral values within the range of ulong
  • short: None, integer literal implicitly converted from int
  • ushort: None, integer literal implicitly converted from int
  • string: Wrap the value with double-quotes, optionally prepended with @
  • null: The literal null

Contributors

Topic Id: 2655

Example Ids: 8831,8832,8833,8834,8835,8836,8837,8838,8839,8840,8841,8842,8843,8844

This site is not affiliated with any of the contributors.