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:
Continue reading C# – How to split a string
- 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
Unit Testing is widely known method of validating results produced by a code in an automated manner. Good test coverage helps with maintaining a code as it is much easier and quicker to spot potential bugs after code changes. How to check if a test suite is effective though? One of the answers is to use Mutation Testing.
The idea is to create mutants which are modified versions of your code and run existing unit tests against these mutants. If a mutation caused test run failure it means a mutant is killed (which is good). If the tests passed then a mutant survived (which is not good). The measurement of the unit tests quality is percentage of the killed mutants where the higher figure is the better. In this approach we expect the test run to fail on mutated code otherwise either not all paths are covered by the unit tests or your tests miss some conditions.
Continue reading Mutation Testing with C# and .NET Core
Any is LINQ functionality to validate whether collection contains at least one element which meets given criteria. Continue reading C# – LINQ Any Examples
First is LINQ functionality to return first item of the collection or throw exception if such item does not exist. Continue reading C# – LINQ First Examples
.NET Framework provides built-in Guid structure which allows to generate unique identifier. Continue reading C# – How to generate Guid
In this article you can find how to convert C# object into JSON using Json.NET (Newtonsoft.Json) library. It is available as a NuGet package for free, so you can easily install it from nuget.org repository. Continue reading C# – Object to JSON Examples
In this article you can find examples how to convert JSON into C# object using Json.NET (Newtonsoft.Json) library. It is available as a NuGet package for free, so you can easily install it from nuget.org repository. Continue reading C# – JSON to Object Examples
Take is LINQ functionality to get given number of elements from the beginning of a collection. Below you can find out how to use it. Continue reading C# – LINQ Take Example