C# Pages

Dot Net Perls has example pages for many languages, with explanations and code side by side (for easy understanding).


Create and loop over a string array. Access array Length and get elements at indexes.C# Array Examples, String Arrays


Create a new List and add elements to it. Loop over its elements with for and foreach.C# List Examples

2D array.

Allocate, loop over and add to 2D arrays. Iterate over elements with nested for-loops.C# 2D Array Examples


Use async and await keywords, along with a Task. Call an async method with await.C# async, await Examples (Task)


Call the Console.WriteLine method. Print values like ints and strings to the screen.C# Console.WriteLine (Print)


Initialize new objects with constructors. Use the new keyword and overloads.C# Constructor Examples


Use DataTable to store data in memory from databases and other data sources.C# DataTable Examples

DateTime format.

Review DateTime format patterns. Call ToString with format codes like MMMM, dd and hh.C# DateTime Format


Compute date and time values. Get relative dates and call DateTime constructors and properties.C# DateTime Examples


Perform fast lookups with string keys. Add elements to Dictionary from System.Collections.Generic.C# Dictionary Examples


Store named and magic constants with enums. Use enums in collections, if and switch.C# enum Examples


Learn ways to handle files. Many methods from the System.IO namespace are available.C# File Handling


Iterate over numbers with for. Increment or decrement an index int from a start to an end value.C# for Loop Examples


Loop over elements with the foreach keyword. Compare other loops and review errors.C# foreach Loop Examples


Use the IEnumerable interface. IEnumerable things can be looped over with foreach.C# IEnumerable Examples

If, else.

Use the if, else-if and else statements to make logical tests in a method.C# if Statement: else if, else


Call the IndexOf method. IndexOf returns the first index of specified character or substring.C# IndexOf Examples


Use KeyValuePair to loop over a Dictionary with foreach. KeyValuePair has 2 member fields.C# KeyValuePair Examples


Review keywords from the C# language. Each keyword has a link to an example and a description.C# Keywords


Use the lambda expression syntax to create function objects. Lambdas have arguments and return values.C# Lambda Expressions


Use extension methods, and query syntax, from the System.Linq namespace.C# LINQ Examples: System.Linq and Extensions

Parse, int.

Convert strings into ints with the int.Parse and int.TryParse methods.C# int.Parse: Convert Strings to Integers


Use the Path class. Path handles file locations in a consistent way, resolving common problems.C# Path Examples


Create a Process to start external EXEs. Include the System.Diagnostics namespace and call Process.Start.C# Process Examples (Process.Start)


Make properties with the get and set keywords. A property is a method that gets or sets a value.C# Property Examples (get, set)


Get random numbers with the Random class. Random has a Next method and can be used as a field.C# Random Number Examples


Learn about the System.Reflection namespace. Use FieldInfo, and call GetMethod and GetProperties.C# Reflection Examples


Use the Regex class and Regex.Match. Review features from System.Text.RegularExpressions.C# Regex.Match Examples: Regular Expressions

Remove duplicates.

Eliminate duplicate elements from a List with Distinct, HashSet, or for-loops. Benchmark the methods on Lists.C# Remove Duplicates From List


Use the Replace method to change all instances of one substring to another. Get the modified string.C# Replace String Examples


Sort arrays using Array.Sort and Lists with Sort. Review the performance of sorting.C# Sort Examples: Arrays and Lists


Use the string.Split method. Call Split with arguments to separate on newlines, spaces and words.C# Split String Examples


Use the static keyword. Create static methods, static classes and static constructors.C# Static Method, Class and Constructor

String switch.

Use a switch statement on a string for improved performance. String literal cases can be tested.C# String Switch Examples


Explore string methods: create, search and change strings with built-in code.C# String


Insert values into a string with string.Format. Specify percentages, decimals and padding.C# String Format


Use the Substring method with start and length ints. Substring gets parts of strings.C# Substring Examples


Use a switch statement to branch on a constant in an efficient way. Switch on value types and strings.C# Switch Examples


Create tuples to store immutable data. A tuple has multiple fields of different types.C# Tuple Examples


Loop over numbers and indexes with while. This syntax can be used for infinite loops.C# While Loop Examples
Dot Net Perls
© 2007-2019 Sam Allen. All rights reserved. Written by Sam Allen,