<< Back to C-SHARP
C# Intermediate Language (IL)
Understand the .NET Framework intermediate language. The IL is composed of instructions.Intermediate language. Code exists on many levels. Abstraction is a ladder. At the highest levels of abstraction, we have C# code. At a lower level, we have an intermediate language.
Instructions. The IL has instructions (opcodes) that manipulate the stack. These instructions, called intermediate language opcodes, reside in a relational database called the metadata.
Intro. Compiler theory has 2 parts. In analysis, source code is parsed and a symbol table is derived. Synthesis is where the object code is generated and written to an executable.
Analysis: Source code is parsed and a symbol table is derived. Analysis comes before synthesis.
Synthesis: Object code is generated and written to an executable. Analysis and synthesis result in an intermediate form.
Info: On execution of the intermediate form, another compiler, the JIT compiler, will be invoked and perform even more optimizations.
Example program: C#
using System;
class Program
{
static void Main()
{
int i = 0;
while (i < 10)
{
Console.WriteLine(i);
i++;
}
}
}
Intermediate language for Main method: IL
.method private hidebysig static void Main() cil managed
{
.entrypoint
.maxstack 2
.locals init (
[0] int32 num)
L_0000: ldc.i4.0
L_0001: stloc.0
L_0002: br.s L_000e
L_0004: ldloc.0
L_0005: call void [mscorlib]System.Console::WriteLine(int32)
L_000a: ldloc.0
L_000b: ldc.i4.1
L_000c: add
L_000d: stloc.0
L_000e: ldloc.0
L_000f: ldc.i4.s 10
L_0011: blt.s L_0004
L_0013: ret
}
IL for Main method. In the second part of the text, you can see the intermediate form of the Main method. This is generated from the C# code.
And: At L_0000, you can see that the constant number zero is pushed onto the evaluation stack through the instruction ldc.
const
Branch. The instruction "br" indicates a branch. This is a conditional instruction that will change what instruction is executed next based on the condition.
Tip: In the C# language, things such as goto, while, for, break, and return may be implemented with variants of the branch instruction.
Call method. Before Console.WriteLine is called, the location of the local variable we are writing is pushed to the evaluation stack. This is used as an argument.
ConsoleIncrement. In IL, an increment is implemented by pushing a constant one to the evaluation stack, and then using the add arithmetic instruction to increment.
Loop instructions. The line L_0011 implements another instruction that returns control to the beginning of the loop if the condition is met. This is another branch.
Note: Branch instructions use labels in the intermediate language. Branches are basically goto statements at the lower level.
IL Disassembler. To gain an understanding of the C# language, I recommend that you inspect the intermediate language for all the code you write.
IL DisassemblerTip: IL Disassembler is provided with Visual Studio. We use it to look at the intermediate language.
Bne. If-statements are translated into branch instructions. One such intermediate language instruction, bne, stands for branch if not equal.
First: The important method here is called A(). If its argument is equal to 1, it writes something to the console.
Here: The constant 1 is pushed with ldc. And the bne instruction is used. It branches based on the constant.
Finally: If the two values on the top of the stack (the constant 1 and the argument int) are not equal, we jump forward to line IL_000f.
C# program that uses bne instruction
using System;
class Program
{
static void Main()
{
A(0);
A(1);
A(2);
}
static void A(int value)
{
if (value == 1)
{
Console.WriteLine("Hi");
}
else
{
Console.WriteLine("Bye");
}
}
}
Output
Bye
Hi
Bye
A method: IL
.method private hidebysig static void A(int32 'value') cil managed
{
// Code size 26 (0x1a)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldc.i4.1
IL_0002: bne.un.s IL_000f
IL_0004: ldstr "Hi"
IL_0009: call void [mscorlib]System.Console::WriteLine(string)
IL_000e: ret
IL_000f: ldstr "Bye"
IL_0014: call void [mscorlib]System.Console::WriteLine(string)
IL_0019: ret
} // end of method Program::A
Call. A call instruction invokes a static or Shared method. We learn about the call instruction in the .NET Framework's intermediate language.
Example: In the Main method, we create an instance of Program and call its instance method A. Finally we call the static method B.
C# program that uses instance and static methods
class Program
{
void A()
{
}
static void B()
{
}
static void Main()
{
Program p = new Program();
p.A();
Program.B();
}
}
IL
.method private hidebysig static void Main() cil managed
{
.entrypoint
// Code size 18 (0x12)
.maxstack 1
.locals init ([0] class Program p)
IL_0000: newobj instance void Program::.ctor()
IL_0005: stloc.0
IL_0006: ldloc.0
IL_0007: callvirt instance void Program::A()
IL_000c: call void Program::B()
IL_0011: ret
} // end of method Program::Main
Callvirt. This is an intermediate language instruction. It is used on instance methods. The call instruction meanwhile is used on static methods.
Code that has an instance method: C#
class Test
{
public int M()
{
return 0;
}
}
class Program
{
static void Main()
{
Test t = new Test();
int i = t.M();
}
}
IL of Main method
.method private hidebysig static void Main() cil managed
{
.entrypoint
.maxstack 1
.locals init (
[0] class Test t)
L_0000: newobj instance void Test::.ctor()
L_0005: stloc.0
L_0006: ldloc.0
L_0007: callvirt instance int32 Test::M()
L_000c: pop
L_000d: ret
}
Code that has a static method: C#
class Test
{
static public int M()
{
return 0;
}
}
class Program
{
static void Main()
{
int i = Test.M();
}
}
IL of Main method
.method private hidebysig static void Main() cil managed
{
.entrypoint
.maxstack 8
L_0000: call int32 Test::M()
L_0005: pop
L_0006: ret
}
Callvirt benchmark. I was working on a program where performance is essential and decided to replace two instance method calls with static method calls.
Result: I found a 1.23% slowdown caused by the callvirt instruction being used.
Callvirt instruction performance data
Instance method and data: 44554 ms
Static method and data: 44008 ms [faster]
Ldarg. This instruction is common. It places an argument onto the evaluation stack. There are several common variants of ldarg in the .NET Framework.
Note: In the IL section of the code example, we see the ldarg.0 and ldarg.1 instructions.
Positions: The 0 and 1 refer to the position of the argument list (formal parameter list).
And: This means ldarg.0 pushes an int32 onto the evaluation stack, and ldarg.1 pushes a string onto the evaluation stack.
Method that has two parameters: C#
static int Something(int a, string b)
{
a += 1;
int y = b.Length + a;
return y;
}
Intermediate Language: IL
.method private hidebysig static int32 Something(int32 a,
string b) cil managed
{
// Code size 16 (0x10)
.maxstack 2
.locals init ([0] int32 y)
IL_0000: ldarg.0
IL_0001: ldc.i4.1
IL_0002: add
IL_0003: starg.s a
IL_0005: ldarg.1
IL_0006: callvirt instance int32 [mscorlib]System.String::get_Length()
IL_000b: ldarg.0
IL_000c: add
IL_000d: stloc.0
IL_000e: ldloc.0
IL_000f: ret
} // end of method Program::Something
Ldc. With the ldc instruction, the .NET Framework loads constant values (such as integers) onto the evaluation stack, making many program constructs possible.
Tip: This program uses six constant values. We pass each constant to Console.WriteLine.
Tip 2: For the values 0 and 8, we find the instructions ldc.i4.0 and ldc.i4.8 are used.
Result: These load a 4-byte integer with value 0 and 8 to the top of the stack.
C# program that uses ldc instructions
using System;
class Program
{
static void Main()
{
Console.WriteLine(0);
Console.WriteLine(8);
Console.WriteLine(9);
Console.WriteLine(-1);
Console.WriteLine('a');
Console.WriteLine(1.23);
}
}
IL
.method private hidebysig static void Main() cil managed
{
.entrypoint
// Code size 47 (0x2f)
.maxstack 8
IL_0000: ldc.i4.0
IL_0001: call void [mscorlib]System.Console::WriteLine(int32)
IL_0006: ldc.i4.8
IL_0007: call void [mscorlib]System.Console::WriteLine(int32)
IL_000c: ldc.i4.s 9
IL_000e: call void [mscorlib]System.Console::WriteLine(int32)
IL_0013: ldc.i4.m1
IL_0014: call void [mscorlib]System.Console::WriteLine(int32)
IL_0019: ldc.i4.s 97
IL_001b: call void [mscorlib]System.Console::WriteLine(char)
IL_0020: ldc.r8 1.23
IL_0029: call void [mscorlib]System.Console::WriteLine(float64)
IL_002e: ret
} // end of method Program::Main
Ldloc. How are local variables used in the intermediate language? In IL locals are allocated separately and accessed by indexes with the ldloc instruction.
Note: In the intermediate language, the ".locals" section indicates that four locals are allocated each time the method is called.
Info: The four local variables are indexed by the numbers 0, 1, 2 and 3. These indexes are used later in the IL.
Method that introduces local variables: C#
static int Example()
{
int a = 1;
string y = "cat";
bool b = false;
int result = a + y.Length + (b ? 1 : 0);
return result;
}
Intermediate language: IL
.method private hidebysig static int32 Example() cil managed
{
// Code size 29 (0x1d)
.maxstack 3
.locals init ([0] int32 a,
[1] string y,
[2] bool b,
[3] int32 result)
IL_0000: ldc.i4.1
IL_0001: stloc.0
IL_0002: ldstr "cat"
IL_0007: stloc.1
IL_0008: ldc.i4.0
IL_0009: stloc.2
IL_000a: ldloc.0
IL_000b: ldloc.1
IL_000c: callvirt instance int32 [mscorlib]System.String::get_Length()
IL_0011: add
IL_0012: ldloc.2
IL_0013: brtrue.s IL_0018
IL_0015: ldc.i4.0
IL_0016: br.s IL_0019
IL_0018: ldc.i4.1
IL_0019: add
IL_001a: stloc.3
IL_001b: ldloc.3
IL_001c: ret
} // end of method Program::Example
Ldsfld. In addition to storing values in static fields, there exists an intermediate language instruction to load values from them.
Field: This program assigns the static field _a to 3. This is done with stsfld.
Next: The ldsfld pushes the value stored in the location of _a onto the top of the evaluation stack.
Then: We load the constant 4 onto the top of the evaluation stack with the ldc.i4.4 instruction.
C# program that has ldsfld instruction
using System;
class Program
{
static int _a;
static void Main()
{
Program._a = 3;
if (Program._a == 4)
{
Console.WriteLine(true);
}
}
}
IL
.method private hidebysig static void Main() cil managed
{
.entrypoint
// Code size 21 (0x15)
.maxstack 8
IL_0000: ldc.i4.3
IL_0001: stsfld int32 Program::_a
IL_0006: ldsfld int32 Program::_a
IL_000b: ldc.i4.4
IL_000c: bne.un.s IL_0014
IL_000e: ldc.i4.1
IL_000f: call void [mscorlib]System.Console::WriteLine(bool)
IL_0014: ret
} // end of method Program::Main
Newarr. The newarr instruction creates a vector. This is a one-dimensional array. Vectors have special support in the .NET Framework.
Quote: One-dimensional arrays that aren't zero-based, and multi-dimensional arrays, are created using newobj rather than newarr (The CLI Annotated Standard).
Next: This program creates an int array of ten elements. The first element is initialized so the compiler does not eliminate any code.
IL: The constant 10 is loaded onto the evaluation stack before newarr is encountered. This causes the array to have ten elements.
C# program that creates new array
using System;
class Program
{
static void Main()
{
int[] array = new int[10];
array[0] = 1;
}
}
Intermediate representation: IL
.method private hidebysig static void Main() cil managed
{
.entrypoint
// Code size 13 (0xd)
.maxstack 3
.locals init ([0] int32[] 'array')
IL_0000: ldc.i4.s 10
IL_0002: newarr [mscorlib]System.Int32
IL_0007: stloc.0
IL_0008: ldloc.0
IL_0009: ldc.i4.0
IL_000a: ldc.i4.1
IL_000b: stelem.i4
IL_000c: ret
} // end of method Program::Main
Ret. Every method executed has a ret instruction. This returns control from the method to the calling method. The instruction sometimes returns a value.
Next: Let's look at a simple C# method that returns an integer value. This method adds two to the argument.
Tip: You can see the argument is accessed with ldarg.0. Finally, the ret instruction appears at the end of the method.
Stack: The evaluation stack at the time ret is executed has the result of the add instruction on it. This is returned.
Method that returns integer: C#
static int Method(int value)
{
return 2 + value;
}
Intermediate language
.method private hidebysig static int32 Method(int32 'value') cil managed
{
// Code size 4 (0x4)
.maxstack 8
IL_0000: ldc.i4.2
IL_0001: ldarg.0
IL_0002: add
IL_0003: ret
} // end of method Program::Method
Stelem. This stores a value inside an array element. Its performance depends on the type of the element and array. We test stelem in some C# programs.
Newarr: When you assign elements in an array, the array itself is pushed onto the stack (newarr).
Next: The index you are using in the array is pushed onto the stack (ldc), and the value you want to put into the array is pushed (ldloc).
Program 1 in C#
class Program
{
static void Main()
{
char[] c = new char[100];
c[0] = 'f';
}
}
Program 1 in IL
.method private hidebysig static void Main() cil managed
{
.entrypoint
.maxstack 3
.locals init (
[0] char[] c)
L_0000: ldc.i4.s 100
L_0002: newarr char
L_0007: stloc.0
L_0008: ldloc.0
L_0009: ldc.i4.0
L_000a: ldc.i4.s 0x66
L_000c: stelem.i2
L_000d: ret
}
Program 2 in C#
class Program
{
static void Main()
{
int[] i = new int[100];
i[0] = 5;
}
}
Program 2 in IL
.method private hidebysig static void Main() cil managed
{
.entrypoint
.maxstack 3
.locals init (
[0] int32[] i)
L_0000: ldc.i4.s 100
L_0002: newarr int32
L_0007: stloc.0
L_0008: ldloc.0
L_0009: ldc.i4.0
L_000a: ldc.i4.5
L_000b: stelem.i4
L_000c: ret
}
Stelem benchmark. Could certain value type elements be faster than others? My previous research in C indicated that the unsigned integer data type is most efficient.
Result: Uint32 was the fastest element type to set in an array. Char was slowest of the three tests.
Benchmark results
char array: 5208 ms
int32 array: 4321 ms
uint32 array: 4125 ms
Stsfld. What is the stsfld instruction? This stores the value on top of the evaluation stack into a static field. We demonstrate this instruction.
However: In the intermediate language, we load a constant value 3 (ldc.i4.3) onto the top of the evaluation stack.
Then: We have a stsfld with the argument being the address of _a. So the top value (3) is stored into the location pointed to by _a.
C# program that has stsfld instruction
using System;
class Program
{
static int _a;
static void Main()
{
Program._a = 3;
if (Program._a == 4)
{
Console.WriteLine(true);
}
}
}
IL
.method private hidebysig static void Main() cil managed
{
.entrypoint
// Code size 21 (0x15)
.maxstack 8
IL_0000: ldc.i4.3
IL_0001: stsfld int32 Program::_a
IL_0006: ldsfld int32 Program::_a
IL_000b: ldc.i4.4
IL_000c: bne.un.s IL_0014
IL_000e: ldc.i4.1
IL_000f: call void [mscorlib]System.Console::WriteLine(bool)
IL_0014: ret
} // end of method Program::Main
Switch. The switch instruction is implemented with a jump table. The switch keyword—in the C# language—is typically compiled to a switch instruction.
IL: In the intermediate language, we see the instruction switch (IL_0020, IL_0027, IL_002e).
Note: Those three identifiers point to lines, which are underlined. So the switch jumps to locations.
C# program that uses switch statement
using System;
class Program
{
static void Main()
{
int i = int.Parse("1");
switch (i)
{
case 0:
Console.WriteLine(0);
break;
case 1:
Console.WriteLine(1);
break;
case 2:
Console.WriteLine(2);
break;
}
}
}
Intermediate language
.method private hidebysig static void Main() cil managed
{
.entrypoint
// Code size 53 (0x35)
.maxstack 1
.locals init ([0] int32 i,
[1] int32 CS$0$0000)
IL_0000: ldstr "1"
IL_0005: call int32 [mscorlib]System.Int32::Parse(string)
IL_000a: stloc.0
IL_000b: ldloc.0
IL_000c: stloc.1
IL_000d: ldloc.1
IL_000e: switch (
IL_0020,
IL_0027,
IL_002e)
IL_001f: ret
IL_0020: ldc.i4.0
IL_0021: call void [mscorlib]System.Console::WriteLine(int32)
IL_0026: ret
IL_0027: ldc.i4.1
IL_0028: call void [mscorlib]System.Console::WriteLine(int32)
IL_002d: ret
IL_002e: ldc.i4.2
IL_002f: call void [mscorlib]System.Console::WriteLine(int32)
IL_0034: ret
} // end of method Program::Main
A summary. The intermediate language is not needed every day. It usually goes without notice. But it opens up a new way of understanding what C# code does.
Related Links:
- C# Array Examples, String Arrays
- C# ArrayList Examples
- C# ArraySegment: Get Array Range, Offset and Count
- C# break Statement
- C# Buffer BlockCopy Example
- C# BufferedStream: Optimize Read and Write
- 404 Not Found
- C# 24 Hour Time Formats
- C# 2D Array Examples
- 7 Zip Command Line Examples
- C# 7 Zip Executable (Process.Start)
- C# All Method: All Elements Match a Condition
- C# Alphabetize String
- C# Alphanumeric Sorting
- C# Arithmetic Expression Optimization
- C# Array.AsReadOnly Method (ObjectModel)
- C# Array.BinarySearch Method
- C# Array.Clear Examples
- C# Array.IndexOf, LastIndexOf: Search Arrays
- C# async, await Examples
- C# Attribute Examples
- C# Average Method
- C# BackgroundWorker
- C# base Keyword
- C# String Between, Before, After
- C# Binary Representation int (Convert, toBase 2)
- C# BinarySearch List
- C# bool Array (Memory Usage, One Byte Per Element)
- C# bool.Parse, TryParse: Convert String to Bool
- C# bool Type
- C# Array Length Property, Get Size of Array
- C# Button Example
- C# Byte Array: Memory Usage, Read All Bytes
- C# Byte and sbyte Types
- C# Capacity for List, Dictionary
- C# Case Insensitive Dictionary
- C# case Example (Switch Case)
- C# Char Array
- C# Checked and Unchecked Keywords
- C# CheckedListBox: Windows Forms
- C# Color Table
- C# Color Examples: FromKnownColor, FromName
- C# ColorDialog Example
- C# Comment: Single Line and Multiline
- C# Concat Extension: Combine Lists and Arrays
- C# Conditional Attribute
- C# Console Color, Text and BackgroundColor
- C# String Clone() method
- C# Constructor Examples
- C# Contains Extension Method
- C# String GetTypeCode() method
- C# String ToLowerInvariant() method
- C# Customized Dialog Box
- C# DataColumn Example: Columns.Add
- C# DataGridView Add Rows
- DataGridView Columns, Edit Columns Dialog
- C# DataGridView Row Colors (Alternating)
- C# DataGridView Tutorial
- C# DataGridView
- C# DataRow Examples
- C# DataSet Examples
- C# DataSource Example
- C# DataTable Compare Rows
- C# DataTable foreach Loop
- C# DataTable RowChanged Example: AcceptChanges
- C# DataTable Select Example
- C# DataTable Examples
- C# DataView Examples
- C# String ToString() method
- C# String ToUpper() method
- C# Digit Separator
- C# DateTime.MinValue (Null DateTime)
- C# DateTime.Month Property
- C# DateTime.Parse: Convert String to DateTime
- C# DateTime Subtract Method
- C# Decompress GZIP
- C# Remove Duplicates From List
- C# dynamic Keyword
- C# ElementAt, ElementAtOrDefault Use
- C# Encapsulate Field
- C# Enum Array Example, Use Enum as Array Index
- C# enum Flags Attribute Examples
- C# Enum ToString: Convert Enum to String
- C# enum Examples
- C# Enumerable.Range, Repeat and Empty
- C# Environment Type
- C# EventLog Example
- C# Exception Handling
- C# explicit and implicit Keywords
- C# Factory Design Pattern
- C# File.Copy Examples
- C# typeof and nameof Operators
- C# String TrimEnd() method
- C# var Examples
- C# virtual Keyword
- C# void Method, Return No Value
- C# volatile Example
- C# WebBrowser Control (Navigate Method)
- C# WebClient: DownloadData, Headers
- C# Where Method and Keyword
- C# String TrimStart() method
- C# delegate Keyword
- C# descending, ascending Keywords
- C# while Loop Examples
- C# Whitespace Methods: Convert UNIX, Windows Newlines
- C# XmlReader, Parse XML File
- C# XmlTextReader
- C# XmlTextWriter
- C# XmlWriter, Create XML File
- C# XOR Operator (Bitwise)
- C# yield Example
- C# float Numbers
- FlowLayoutPanel Control
- C# Focused Property
- C# FolderBrowserDialog Control
- C# Font Type: FontFamily and FontStyle
- C# FontDialog Example
- C# for Loop Examples
- C# foreach Loop Examples
- ForeColor, BackColor: Windows Forms
- C# Form: Event Handlers
- C# Contains String Method
- C# ContainsValue Method (Value Exists in Dictionary)
- C# ContextMenuStrip Example
- C# continue Keyword
- C# Control: Windows Forms
- C# Windows Forms Controls
- C# Convert Char Array to String
- C# Convert Char to String
- C# Convert Days to Months
- C# Convert String to Byte Array
- C# String Format
- C# Func Object (Lambda That Returns a Value)
- C# GC.Collect Examples: CollectionCount, GetTotalMemory
- C# Path.GetDirectoryName (Remove File From Path)
- C# goto Examples
- C# HttpClient Example: System.Net.Http
- ASP.NET HttpContext Request Property
- IL Disassembler Tutorial
- C# Intermediate Language (IL)
- C# IndexOf Examples
- C# IndexOfAny Examples
- C# Initialize Array
- C# Initialize List
- C# InitializeComponent Method: Windows Forms
- C# Inline Optimization
- C# Dictionary Equals: If Contents Are the Same
- C# Dictionary Versus List Loop
- C# Dictionary Order, Use Keys Added Last
- C# Dictionary Size and Performance
- C# Dictionary Versus List Lookup Time
- C# Dictionary Examples
- C# Get Directory Size (Total Bytes in All Files)
- C# Directory Type
- C# Distinct Method, Get Unique Elements Only
- C# Divide by Powers of Two (Bitwise Shift)
- C# Divide Numbers (Cast Ints)
- C# DomainUpDown Control Example
- C# Double Type: double.MaxValue, double.Parse
- C# Remove Duplicate Chars
- C# IEqualityComparer
- C# If Preprocessing Directive: Elif and Endif
- C# If Versus Switch Performance
- C# if Statement
- C# int.MaxValue, MinValue (Get Lowest Number)
- C# Program to reverse number
- C# Int and uint Types
- C# Integer Append Optimization
- C# Keywords
- C# Label Example: Windows Forms
- C# Lambda Expressions
- C# LastIndexOf Examples
- C# Last, LastOrDefault Methods
- C# Mutex Example (OpenExisting)
- C# Named Parameters
- C# Let Keyword (Use Variable in Query Expression)
- C# Levenshtein Distance
- C# LinkLabel Example: Windows Forms
- C# LINQ
- C# List Add Method, Append Element to List
- C# List AddRange, InsertRange (Append Array to List)
- C# List Clear Example
- C# List Contains Method
- C# List Remove Examples
- C# List Examples
- C# ListBox Tutorial (DataSource, SelectedIndex)
- C# ListView Tutorial: Windows Forms
- C# Maze Pathfinding Algorithm
- C# Memoization
- C# Memory Usage for Arrays of Objects
- C# MessageBox.Show Examples
- C# Method Call Depth Performance
- C# Method Parameter Performance
- C# Method Size Optimization
- C# Multidimensional Array
- C# MultiMap Class (Dictionary of Lists)
- C# Optimization
- C# new Keyword
- C# NotifyIcon: Windows Forms
- C# NotImplementedException
- C# Null Array
- C# String GetType() method
- C# Null Coalescing and Null Conditional Operators
- C# Null List (NullReferenceException)
- C# Numeric Casts
- C# NumericUpDown Control: Windows Forms
- C# object.ReferenceEquals Method
- C# Object Examples
- C# Optional Parameters
- C# Prime Number
- C# OrderBy, OrderByDescending Examples
- C# Process Examples (Process.Start)
- Panel, Windows Forms (Create Group of Controls)
- C# Path Examples
- C# Get Percentage From Number With Format String
- ASP.NET PhysicalApplicationPath
- C# PictureBox: Windows Forms
- C# PNG Optimization
- C# Position Windows: Use WorkingArea and Location
- Visual Studio Post Build, Pre Build Macros
- C# ProfileOptimization
- C# ProgressBar Example
- C# Property Examples
- C# PropertyGrid: Windows Forms
- C# Protected and internal Keywords
- C# Public and private Methods
- C# Remove Punctuation From String
- C# Query Windows Forms (Controls.OfType)
- C# Queryable: IQueryable Interface and AsQueryable
- ASP.NET QueryString Examples
- C# Queue Collection: Enqueue
- C# RadioButton Use: Windows Forms
- C# ReadOnlyCollection Use (ObjectModel)
- C# Recursion Optimization
- C# Recursive File List: GetFiles With AllDirectories
- C# ref Keyword
- C# Reflection Examples
- C# Regex.Escape and Unescape Methods
- C# StringBuilder Examples
- C# StringComparison and StringComparer
- C# StringReader Class (Get Parts of Strings)
- C# String GetEnumerator() method
- C# String GetHashCode() method
- C# Regex Versus Loop: Use For Loop Instead of Regex
- C# Regex.Match Examples: Regular Expressions
- C# RemoveAll: Use Lambda to Delete From List
- C# Replace String Examples
- ASP.NET Response.BinaryWrite
- ASP.NET Response.Write
- C# Return Optimization: out Performance
- C# SaveFileDialog: Use ShowDialog and FileName
- C# Scraping HTML Links
- C# sealed Keyword
- C# Seek File Examples: ReadBytes
- C# select new Example: LINQ
- C# Select Method (Use Lambda to Modify Elements)
- C# Serialize List (Write to File With BinaryFormatter)
- C# Settings.settings in Visual Studio
- C# Shuffle Array: KeyValuePair and List
- C# Single and Double Types
- C# Single Instance Windows Form
- C# Snippet Examples
- C# Sort DateTime List
- C# Sort List With Lambda, Comparison Method
- C# Sort Number Strings
- C# Sort Examples: Arrays and Lists
- C# SortedDictionary
- C# SortedList
- C# SortedSet Examples
- C# Split String Examples
- C# String Copy() method
- C# SplitContainer: Windows Forms
- C# SqlClient Tutorial: SqlConnection, SqlCommand
- C# SqlCommand Example: SELECT TOP, ORDER BY
- C# SqlCommandBuilder Example: GetInsertCommand
- C# SqlConnection Example: Using, SqlCommand
- C# SqlDataAdapter Example
- C# SqlDataReader: GetInt32, GetString
- C# SqlParameter Example: Constructor, Add
- C# Stack Collection: Push, Pop
- C# Static List: Global List Variable
- C# Static Regex
- C# Static String
- C# static Keyword
- C# StatusStrip Example: Windows Forms
- C# String Chars (Get Char at Index)
- C# string.Concat Examples
- C# String Interpolation Examples
- C# string.Join Examples
- C# String Performance, Memory Usage Info
- C# String Property
- C# String Slice, Get Substring Between Indexes
- C# String Switch Examples
- C# String
- C# StringBuilder Append Performance
- C# StringBuilder Cache
- C# ToBase64String (Data URI Image)
- C# Struct Versus Class
- C# struct Examples
- C# Substring Examples
- C# Numeric Suffix Examples
- C# switch Examples
- C# String IsNormalized() method
- C# TabControl: Windows Forms
- TableLayoutPanel: Windows Forms
- C# Take and TakeWhile Examples
- C# Task Examples (Task.Run, ContinueWith and Wait)
- C# Ternary Operator
- C# Text Property: Windows Forms
- C# TextBox.AppendText Method
- C# TextBox Example
- C# TextChanged Event
- C# TextFieldParser Examples: Read CSV
- C# ThreadStart and ParameterizedThreadStart
- C# throw Keyword Examples
- C# Timer Examples
- C# TimeSpan Examples
- C# TrimEnd and TrimStart
- C# True and False
- C# Truncate String
- C# String ToLower() method
- C# String ToCharArray() method
- C# String ToUpperInvariant() method
- C# String Trim() method
- C# Assign Variables Optimization
- C# Array.Resize Examples
- C# Array.Sort: Keys, Values and Ranges
- C# Array.Reverse Example
- C# Array Slice, Get Elements Between Indexes
- C# Array.TrueForAll: Use Lambda to Test All Elements
- C# ArrayTypeMismatchException
- C# as: Cast Examples
- C# ASCII Table
- C# ASCII Transformation, Convert Char to Index
- C# AsEnumerable Method
- C# AsParallel Example
- ASP.NET AspLiteral
- C# BaseStream Property
- C# Console.Beep Example
- C# Benchmark
- C# BinaryReader Example (Use ReadInt32)
- C# BinaryWriter Type
- C# BitArray Examples
- C# BitConverter Examples
- C# Bitcount Examples
- C# Bool Methods, Return True and False
- C# bool Sort Examples (True to False)
- C# Caesar Cipher
- C# Cast Extension: System.Linq
- C# Cast to Int (Convert Double to Int)
- C# Cast Examples
- C# catch Examples
- C# Change Characters in String (ToCharArray, For Loop)
- C# Char Combine: Get String From Chars
- C# char.IsDigit (If Char Is Between 0 and 9)
- C# char.IsLower and IsUpper
- C# Character Literal (const char)
- C# Char Lowercase Optimization
- C# Char Test (If Char in String Equals a Value)
- C# char.ToLower and ToUpper
- C# char Examples
- C# abstract Keyword
- C# Action Object (Lambda That Returns Void)
- C# Aggregate: Use Lambda to Accumulate Value
- C# AggressiveInlining: MethodImpl Attribute
- C# Anagram Method
- C# And Bitwise Operator
- C# Anonymous Function (Delegate With No Name)
- C# Any Method, Returns True If Match Exists
- C# StringBuilder Append and AppendLine
- C# StringBuilder AppendFormat
- ASP.NET appSettings Example
- C# ArgumentException: Invalid Arguments
- C# Array.ConvertAll, Change Type of Elements
- C# Array.Copy Examples
- C# Array.CreateInstance Method
- C# Array and Dictionary Test, Integer Lookups
- C# Array.Exists Method, Search Arrays
- C# Array.Find Examples, Search Array With Lambda
- C# Array.ForEach: Use Lambda on Every Element
- C# Array Versus List Memory Usage
- C# Array Property, Return Empty Array
- C# CharEnumerator
- C# Chart, Windows Forms (Series and Points)
- C# CheckBox: Windows Forms
- C# class Examples
- C# Clear Dictionary: Remove All Keys
- C# Clone Examples: ICloneable Interface
- C# Closest Date (Find Dates Nearest in Time)
- C# Combine Arrays: List, Array.Copy and Buffer.BlockCopy
- C# Combine Dictionary Keys
- C# ComboBox: Windows Forms
- C# CompareTo Int Method
- C# Comparison Object, Used With Array.Sort
- C# Compress Data: GZIP
- C# Console.Read Method
- C# Console.ReadKey Example
- C# Console.ReadLine Example (While Loop)
- C# Console.SetOut and Console.SetIn
- C# Console.WindowHeight
- C# Console.Write, Append With No Newline
- C# Console.WriteLine (Print)
- C# const Example
- C# Constraint Puzzle Solver
- C# Count Characters in String
- C# Count, Dictionary (Get Number of Keys)
- C# Count Letter Frequencies
- C# Count Extension Method: Use Lambda to Count
- C# CSV Methods (Parse and Segment)
- C# DataRow Field Method: Cast DataTable Cell
- C# Get Day Count Elapsed From DateTime
- C# DateTime Format
- C# DateTime.Now (Current Time)
- C# DateTime.Today (Current Day With Zero Time)
- C# DateTime.TryParse and TryParseExact
- C# DateTime Examples
- C# DateTimePicker Example
- C# Debug.Write Examples
- C# Visual Studio Debugging Tutorial
- C# decimal Examples
- C# DayOfWeek
- C# Enum.Format Method (typeof Enum)
- C# Enum.GetName, GetNames: Get String Array From Enum
- C# Enum.Parse, TryParse: Convert String to Enum
- C# Error and Warning Directives
- C# ErrorProvider Control: Windows Forms
- C# event Examples
- C# Get Every Nth Element From List (Modulo)
- C# Excel Interop Example
- C# Except (Remove Elements From Collection)
- C# Extension Method
- C# extern alias Example
- C# Convert Feet, Inches
- C# File.Delete
- C# File Equals: Compare Files
- C# File.Exists Method
- C# try Keyword
- C# TryGetValue (Get Value From Dictionary)
- C# Tuple Examples
- C# Type Class: Returned by typeof, GetType
- C# TypeInitializationException
- C# Union: Combine and Remove Duplicate Elements
- C# Unreachable Code Detected
- C# Unsafe Keyword: Fixed, Pointers
- C# Uppercase First Letter
- C# Uri and UriBuilder Classes
- C# Using Alias Example
- C# using Statement: Dispose and IDisposable
- C# value Keyword
- C# ValueTuple Examples (System.ValueTuple, ToTuple)
- C# ValueType Examples
- C# Variable Initializer for Class Field
- C# Word Count
- C# Word Interop: Microsoft.Office.Interop.Word
- C# XElement Example (XElement.Load, XName)
- C# Zip Method (Use Lambda on Two Collections)
- C# File.Move Method, Rename File
- C# File.Open Examples
- C# File.ReadAllBytes, Get Byte Array From File
- C# File.ReadAllLines, Get String Array From File
- C# File.ReadAllText, Get String From File
- C# File.ReadLines, Use foreach Over Strings
- C# File.Replace Method
- C# FileInfo Length, Get File Size
- C# FileInfo Examples
- C# File Handling
- C# Filename With Date Example (DateTime.Now)
- C# FileNotFoundException (catch Example)
- C# FileStream Length, Get Byte Count From File
- C# FileStream Example, File.Create
- C# FileSystemWatcher Tutorial (Changed, e.Name)
- C# finally Keyword
- C# First Sentence
- C# FirstOrDefault (Get First Element If It Exists)
- C# Fisher Yates Shuffle: Generic Method
- C# fixed Keyword (unsafe)
- C# Flatten Array (Convert 2D to 1D)
- C# First Words in String
- C# First (Get Matching Element With Lambda)
- C# ContainsKey Method (Key Exists in Dictionary)
- C# Convert ArrayList to Array (Use ToArray)
- C# Convert ArrayList to List
- C# Convert Bool to Int
- C# Convert Bytes to Megabytes
- C# Convert Degrees Celsius to Fahrenheit
- C# Convert Dictionary to List
- C# Convert Dictionary to String (Write to File)
- C# Convert List to Array
- C# Convert List to DataTable (DataGridView)
- C# Convert List to String
- C# Convert Miles to Kilometers
- C# Convert Milliseconds, Seconds, Minutes
- C# Convert Nanoseconds, Microseconds, Milliseconds
- C# Convert String Array to String
- C# Convert TimeSpan to Long
- C# Convert Types
- C# Copy Dictionary
- C# Count Elements in Array and List
- C# FromOADate and Excel Dates
- C# Generic Class, Generic Method Examples
- C# GetEnumerator: While MoveNext, Get Current
- C# GetHashCode (String Method)
- C# Thumbnail Image With GetThumbnailImage
- C# GetType Method
- C# Global Variable Examples (Public Static Property)
- ASP.NET Global Variables Example
- C# Group By Operator: LINQ
- GroupBox: Windows Forms
- C# GroupBy Method: LINQ
- C# GroupJoin Method
- C# GZipStream Example (DeflateStream)
- C# HashSet Examples
- C# Hashtable Examples
- HelpProvider Control Use
- C# HTML and XML Handling
- C# HtmlEncode and HtmlDecode
- C# HtmlTextWriter Example
- C# HttpUtility.HtmlEncode Methods
- C# HybridDictionary
- C# default Operator
- C# DefaultIfEmpty Method
- C# Define and Undef Directives
- C# Destructor
- C# DialogResult: Windows Forms
- C# Dictionary, Read and Write Binary File
- C# Dictionary Memory
- C# Dictionary Optimization, Increase Capacity
- C# Dictionary Optimization, Test With ContainsKey
- C# DictionaryEntry Example (Hashtable)
- C# Directives
- C# Directory.CreateDirectory, Create New Folder
- C# Directory.GetFiles Example (Get List of Files)
- C# DivideByZeroException
- C# DllImport Attribute
- C# Do While Loop Example
- C# DriveInfo Examples
- C# DropDownItems Control
- C# IComparable Example, CompareTo: Sort Objects
- C# IDictionary Generic Interface
- C# IEnumerable Examples
- C# IList Generic Interface: List and Array
- C# Image Type
- C# ImageList Use: Windows Forms
- C# Increment String That Contains a Number
- C# Increment, Preincrement and Decrement Ints
- Dot Net Perls
- C# Indexer Examples (This Keyword, get and set)
- C# IndexOutOfRangeException
- C# Inheritance
- C# Insert String Examples
- C# int Array
- C# Interface Examples
- C# Interlocked Examples: Add, CompareExchange
- C# Intersect: Get Common Elements
- C# InvalidCastException
- C# InvalidOperationException: Collection Was Modified
- C# IOException Type: File, Directory Not Found
- C# IOrderedEnumerable (Query Expression With orderby)
- C# is: Cast Examples
- C# IsFixedSize, IsReadOnly and IsSynchronized Arrays
- C# string.IsNullOrEmpty, IsNullOrWhiteSpace
- C# IsSorted Method: If Array Is Already Sorted
- C# Jagged Array Examples
- C# join Examples (LINQ)
- C# KeyCode Property and KeyDown
- C# KeyNotFoundException: Key Not Present in Dictionary
- C# KeyValuePair Examples
- C# Line Count for File
- C# Line Directive
- C# LinkedList
- C# List CopyTo (Copy List Elements to Array)
- C# List Equals (If Elements Are the Same)
- C# List Find and Exists Examples
- C# List Insert Performance
- ASP.NET LiteralControl Example
- C# Locality Optimizations (Memory Hierarchy)
- C# lock Keyword
- C# Long and ulong Types
- C# Loop Over String Chars: Foreach, For
- C# Loop Over String Array
- C# Main args Examples
- C# Map Example
- ASP.NET MapPath: Virtual and Physical Paths
- C# Mask Optimization
- C# MaskedTextBox Example
- C# Math.Abs: Absolute Value
- C# Math.Ceiling Usage
- C# Math.Floor Method
- C# Math.Max and Math.Min Examples
- C# Math.Pow Method, Exponents
- C# Math.Round Examples: MidpointRounding
- C# Math Type
- C# Max and Min: Get Highest or Lowest Element
- C# MemoryFailPoint and InsufficientMemoryException
- C# MemoryStream: Use Stream on Byte Array
- C# MenuStrip: Windows Forms
- C# Modulo Operator: Get Remainder From Division
- C# MonthCalendar Control: Windows Forms
- C# Multiple Return Values
- C# Multiply Numbers
- C# namespace Keyword
- C# NameValueCollection Usage
- C# Nested Lists: Create 2D List or Jagged List
- C# Nested Switch Statement
- C# Environment.NewLine
- C# Normalize, IsNormalized Methods
- C# Null String Example
- C# null Keyword
- C# Nullable Examples
- C# NullReferenceException and Null Parameter
- C# Object Array
- C# Obsolete Attribute
- C# OfType Examples
- C# OpenFileDialog Example
- C# operator Keyword
- C# Odd and Even Numbers
- C# Bitwise Or
- C# orderby Query Keyword
- C# out Parameter
- C# OutOfMemoryException
- C# OverflowException
- C# Overload Method
- C# Override Method
- C# PadRight and PadLeft: String Columns
- C# Get Paragraph From HTML With Regex
- C# Parallel.For Example (Benchmark)
- C# Parallel.Invoke: Run Methods on Separate Threads
- C# Parameter Optimization
- C# Parameter Passing, ref and out
- C# params Keyword
- C# int.Parse: Convert Strings to Integers
- C# partial Keyword
- C# Path.ChangeExtension
- C# Path Exists Example
- C# Path.GetExtension: File Extension
- C# Path.GetRandomFileName Method
- C# Pragma Directive
- C# Predicate (Lambda That Returns True or False)
- C# Pretty Date Format (Hours or Minutes Ago)
- C# PreviewKeyDown Event
- C# Random Lowercase Letter
- C# Random Paragraphs and Sentences
- C# Random String
- C# Random Number Examples
- C# StreamReader ReadLine, ReadLineAsync Examples
- C# readonly Keyword
- C# Recursion Example
- C# Regex, Read and Match File Lines
- C# Regex Groups, Named Group Example
- C# Regex.Matches Quote Example
- C# Regex.Matches Method: foreach Match, Capture
- C# Regex.Replace, Matching End of String
- C# Regex.Replace, Remove Numbers From String
- C# Regex.Replace, Merge Multiple Spaces
- C# Regex.Replace Examples: MatchEvaluator
- C# Regex.Split, Get Numbers From String
- C# Regex.Split Examples
- C# Regex Trim, Remove Start and End Spaces
- C# RegexOptions.Compiled
- C# RegexOptions.IgnoreCase Example
- C# RegexOptions.Multiline
- C# Region and endregion
- C# Remove Char From String at Index
- C# Remove Element
- C# Remove HTML Tags
- C# Remove String
- C# Reserved Filenames
- C# return Keyword
- C# Reverse String
- C# Reverse Words
- C# Reverse Extension Method
- C# RichTextBox Example
- C# Right String Part
- C# RNGCryptoServiceProvider Example
- C# ROT13 Method, Char Lookup Table
- C# SelectMany Example: LINQ
- C# Sentinel Optimization
- C# SequenceEqual Method (If Two Arrays Are Equal)
- C# Shift Operators (Bitwise)
- C# Short and ushort Types
- C# Single Method: Get Element If Only One Matches
- C# SingleOrDefault
- C# Singleton Pattern Versus Static Class
- C# Singleton Class
- C# sizeof Keyword
- C# Skip and SkipWhile Examples
- C# Sleep Method (Pause)
- C# Sort Dictionary: Keys and Values
- C# Sort by File Size
- C# Sort, Ignore Leading Chars
- C# Sort KeyValuePair List: CompareTo
- C# Sort Strings by Length
- C# Thread.SpinWait Example
- C# Math.Sqrt Method
- C# stackalloc Operator
- C# StackOverflowException
- C# StartsWith and EndsWith String Methods
- C# Static Array
- C# Static Dictionary
- C# Stopwatch Examples
- C# Stream
- C# StreamReader ReadToEnd Example (Read Entire File)
- C# StreamReader ReadToEndAsync Example (Performance)
- C# StreamReader Examples
- C# StreamWriter Examples
- C# String Append (Add Strings)
- C# String Compare and CompareTo Methods
- C# String Constructor (new string)
- C# string.Copy Method
- C# CopyTo String Method: Put Chars in Array
- C# Empty String Examples
- C# String Equals Examples
- C# String For Loop, Count Spaces in String
- C# string.Intern and IsInterned
- C# String IsUpper, IsLower
- C# String Length Property: Get Character Count
- C# String Literal: Newline and Quote Examples
- C# StringBuilder Capacity
- C# StringBuilder Clear (Set Length to Zero)
- C# StringBuilder Data Types
- C# StringBuilder Performance
- C# StringBuilder Equals (If Chars Are Equal)
- C# StringBuilder Memory
- C# StringBuilder ToString: Get String From StringBuilder
- C# StringWriter Class
- C# Sum Method: Add up All Numbers
- C# Switch Char, Test Chars With Cases
- C# Switch Enum
- C# System (using System namespace)
- C# Tag Property: Windows Forms
- C# TextInfo Examples
- C# TextReader, Returned by File.OpenText
- C# TextWriter, Returned by File.CreateText
- C# this Keyword
- C# ThreadPool
- C# Thread Join Method (Join Array of Threads)
- C# ThreadPool.SetMinThreads Method
- C# TimeZone Examples
- C# Get Title From HTML With Regex
- C# ToArray Extension Method
- C# ToCharArray: Convert String to Array
- C# ToDictionary Method
- C# Token
- C# ToList Extension Method
- C# ToLookup Method (Get ILookup)
- C# ToLower and ToUpper: Uppercase and Lowercase Strings
- ToolStripContainer Control: Dock, Properties
- C# ToolTip: Windows Forms
- C# ToString Integer Optimization
- C# ToString: Get String From Object
- C# ToTitleCase Method
- C# TrackBar: Windows Forms
- C# Tree and Nodes Example: Directed Acyclic Word Graph
- C# TreeView Tutorial
- C# Trim Strings
- C# Thread Methods
- C# History
- C# Features
- C# Variables
- C# Data Types
- C# Operators
- C# Keywords
- C# New Features | C# Version Features
- C# Programs
- C# Program to swap numbers without third variable
- C# Program to convert Decimal to Binary
- C# Program to Convert Number in Characters
- C# Program to Print Alphabet Triangle
- C# Program to print Number Triangle
- C# Program to generate Fibonacci Triangle
- C# String Compare() method
- C# String CompareOrdinal() method
- C# String CompareTo() method
- C# String Concat() method
- C# String Contains() method
- C# String CopyTo() method
- C# String EndsWith() method
- C# String Equals() method
- C# String Format() method
- C# String IndexOf() method
- C# String Insert() method
- C# String Intern(String str) method
- C# String IsInterned() method
- C# String Normalize() method
- C# String IsNullOrEmpty() method
- C# String IsNullOrWhiteSpace() method
- C# String Join() method
- C# String LastIndexOf() method
- C# String LastIndexOfAny() method
- C# String PadLeft() method
- C# String PadRight() method
- C# Nullable
- C# String Remove() method
- C# String Replace() method
- C# String Split() method
- C# String StartsWith() method
- C# String SubString() method
- C# Partial Types
- C# Iterators
- C# Delegate Covariance
- C# Delegate Inference
- C# Anonymous Types
- C# Extension Methods
- C# Query Expression
- C# Partial Method
- C# Implicitly Typed Local Variable
- C# Object and Collection Initializer
- C# Auto Implemented Properties
- C# Dynamic Binding
- C# Named and Optional Arguments
- C# Asynchronous Methods
- C# Caller Info Attributes
- C# Using Static Directive
- C# Exception Filters
- C# Await in Catch Finally Blocks
- C# Default Values for Getter Only Properties
- C# Expression Bodied Members
- C# Null Propagator
- C# String Interpolation
- C# nameof operator
- C# Dictionary Initializer
- C# Pattern Matching
- C# Tuples
- C# Deconstruction
- C# Local Functions
- C# Binary Literals
- C# Ref Returns and Locals
- C# Expression Bodied Constructors and Finalizers
- C# Expression Bodied Getters and Setters
- C# Async Main
- C# Default Expression
Related Links
Adjectives
Ado
Ai
Android
Angular
Antonyms
Apache
Articles
Asp
Autocad
Automata
Aws
Azure
Basic
Binary
Bitcoin
Blockchain
C
Cassandra
Change
Coa
Computer
Control
Cpp
Create
Creating
C-Sharp
Cyber
Daa
Data
Dbms
Deletion
Devops
Difference
Discrete
Es6
Ethical
Examples
Features
Firebase
Flutter
Fs
Git
Go
Hbase
History
Hive
Hiveql
How
Html
Idioms
Insertion
Installing
Ios
Java
Joomla
Js
Kafka
Kali
Laravel
Logical
Machine
Matlab
Matrix
Mongodb
Mysql
One
Opencv
Oracle
Ordering
Os
Pandas
Php
Pig
Pl
Postgresql
Powershell
Prepositions
Program
Python
React
Ruby
Scala
Selecting
Selenium
Sentence
Seo
Sharepoint
Software
Spellings
Spotting
Spring
Sql
Sqlite
Sqoop
Svn
Swift
Synonyms
Talend
Testng
Types
Uml
Unity
Vbnet
Verbal
Webdriver
What
Wpf