C# – 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. List … Continue reading C# – How to check if an item exists in a list

C# – 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. Array of integers Let’s consider an array of integers. Below are presented five different methods of creating 3 elements array, … Continue reading C# – How to initialize an array

C# – 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. … Continue reading C# – How to generate random password

C# – How to get unique items from list

The easiest way of getting unique items from list is LINQ’s Distinct() method. In this article you’ll see how to use it with both built-in types (like collection of integers) and custom types (like collection of complex type objects). Get unique values from collection of integers Let’s start with creating example list of items where … Continue reading C# – How to get unique items from list