HomeSearch

C# Pages

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

Array.

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

List.

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

Async.

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

Console.

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

Constructor.

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

DataTable.

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

DateTime.

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

Dictionary.

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

Enum.

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

File.

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

For.

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

Foreach.

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

IEnumerable.

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

IndexOf.

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

KeyValuePair.

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

Keywords.

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

Lambda.

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

LINQ.

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

Path.

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

Process.

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

Property.

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

Random.

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

Reflection.

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

Regex.

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

Replace.

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

Sort.

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

Split.

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

Static.

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

String.

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

String.Format.

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

Substring.

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

Switch.

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

Tuple.

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

While.

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