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 password
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
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.Continue reading C# – How to generate random number
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).Continue reading C# – How to get unique items from list
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;
- define maximum number of substrings in output array;
- define split options like removing empty elements from returned collection.
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.Continue reading C# – How to convert string to int
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.Continue reading C# – How to check if string contains only digits
.NET Framework provides built-in Guid structure which allows to generate unique identifier. Continue reading C# – How to generate Guid