Average is a LINQ functionality which calculates average value of given collection. It works with both collections of primitive values and complex objects. Below article provides example of each one.
Continue reading C# – LINQ Average ExamplesC# – LINQ Sum Examples
Sum is a LINQ functionality which calculates total number of numeric items of a collection. In this article you can find examples of usage with list of primitive types (in our case integers) and also list of complex types.
Continue reading C# – LINQ Sum ExamplesC# – How to check if an item exists in a list
In this article we’ll present and compare two functions which offer us a possibility to check whether an item exists in a given list. These functions are Exists and Contains, both available in System.Collections.Generic namespace. Provided examples are for two different lists: one containing integers and other one containing objects of custom created class.
Continue reading C# – How to check if an item exists in a listC# – How to convert string to enum
In this article we’ll explain the way of converting string to any enumeration type. There are two easiest ways to do so: using Parse or TryParse method. Examples of both are presented below. If you need to read how to create and use enums, please see following page: How to use enum.
Continue reading C# – How to convert string to enumC# – How to use enum
Enum is value type containing a set of constants representing associated integers. These integers can be assigned automatically, starting from 0 and incremented by 1 on consecutive items, or assigned directly by programmer. This article presents the way of implementing our own enum and also examples of its usage.
Continue reading C# – How to use enumC# – How to initialize an array
Array is a fixed size collection of variables representing the same type. Array can store both built-in primitive types (like integer) and custom objects. In this article we’ll present different ways of initializing such arrays.
Continue reading C# – How to initialize an arrayC# – LINQ GroupBy Examples
GroupBy is a LINQ functionality which allows to group items from a collection based on a given key. It’s an equivalent to SQL’s GROUP BY clause. In this article we’ll show various examples of usage, starting from the simplest grouping by one key, through grouping by multiple keys, custom result selector and all of that in two variants: Lambda and Query expression.
Continue reading C# – LINQ GroupBy ExamplesC# – LINQ Join Examples
Join is a LINQ functionality to combine two collections and produce a single result set. Connection happens by comparing items from both series. When there is a match then such pair is one of the output elements.
Continue reading C# – LINQ Join ExamplesC# – How to generate random password
This article delivers proposal of algorithm to generate random passwords or actually random strings which are generated in safe manner and can be used as passwords, discount codes etc. Also, it is configurable, so that you can easily define expected length of string, pool of available characters or minimal number of occurrences of particular elements. All is encapsulated within a class, ready to reuse in your project. In this articles we’ll go through small code snippets and describe them in details, but full class can be also found at the end.
Continue reading C# – How to generate random passwordC# – How to generate random string
There are situations where you need a random string which is built with specific characters. In this article you’ll see how to generate such string where both length and elements are totally up to you.
Continue reading C# – How to generate random string