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
Category: How To
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 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. Algorithm is very simple. It uses for loop, so that in every iteration it extends an output string with randomly … Continue reading C# – How to generate random string
C# – How to generate random number
Generating random numbers in C# is quick and easy using Random class. It’s built-in functionality which allows to produce integers, doubles and bytes. In this article you can find examples how to use it. Random integers The most basic usage is calling Next function without any parameters against an object of Random class. It returns … Continue reading C# – How to generate random number
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
C# – How to split a string
String can be split into collection of substrings based on a defined character (separator) using Split() function. Split is part of String class which exists in the System namespace. Split function is overloaded and has various forms which allow to: pass separator as a single character, array of characters, single string or array of strings; … Continue reading C# – How to split a string
C# – How to convert string to int
There are three easiest ways which allow you to convert string data type to int: Parse method TryParse method Convert class In the following article I’ll explain each one and show the example of its usage. Parse method Basic form of Parse method receives string as an input parameter and returns converted value as an … Continue reading C# – How to convert string to int
C# – How to check if string contains only digits
There are plenty of methods to achieve this but even though it’s simple task you need to specify requirements like: are white spaces allowed? how to treat empty string? what’s the maximum length of the string? In this article I want to describe 3 different ideas how to solve this problem. Custom function Let’s say … Continue reading C# – How to check if string contains only digits
C# – How to generate Guid
.NET Framework provides built-in Guid structure which allows to generate unique identifier. The usage is very simple and requires to call NewGuid function on Guid structure. Guid guid = Guid.NewGuid(); 1 Guid guid = Guid.NewGuid(); Returned object type is Guid however we can easily convert it to string. var guidString = guid.ToString(); 1 var guidString = … Continue reading C# – How to generate Guid
.NET Framework upgrade
How to upgrade .NET Framework? First of all you need to install desired framework version on both development and client machines. Development machine is an environment where you code and build your project. It requires .NET Framework Developer Pack. Client machine is an environment where your application is used. It requires lighter package .NET Framework … Continue reading .NET Framework upgrade