.NET doesn’t use Newtonsoft by default anymore (since .NET Core 3.0). A lot of the examples online show how to use the new System.Text.Json namespace to extract values from JSON strings by deserializing the strings into full POCO classes (DTOs/ViewModels). If you only want to extract the value of a particular property and don’t want the … Continue reading Parsing a nested value from a JSON string in .NET Core 3 without needing a DTO
Author: csharp.academy
Generating sequential GUIDs which sort correctly in SQL Server in .net
Using a non sequential GUID in either a clustered or non clustered index is not ideal from a performance point of view as non sequential GUIDs are not ever-increasing (like an identity int) so get inserted into the middle of the index rather than the end resulting in increased logical fragmentation and decreased performance. If … Continue reading Generating sequential GUIDs which sort correctly in SQL Server in .net
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
Mutation Testing with C# and .NET Core
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 … Continue reading Mutation Testing with C# and .NET Core
C# – LINQ Any Examples
Any is LINQ functionality to validate whether collection contains at least one element which meets given criteria. Let’s start with example collection of integers: var integers = new List<int>() { 36, 10, 4, 23, 1 }; 1 var integers = new List<int>() { 36, 10, 4, 23, 1 }; First call the Any function without any … Continue reading C# – LINQ Any Examples
C# – LINQ First Examples
First is LINQ functionality to return first item of the collection or throw exception if such item does not exist. First is overloaded method which can be used with either zero or one parameter. The first option just returns first element and the second one allows to define condition which needs to be met. 1. Collection … Continue reading C# – LINQ First Examples
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
C# – Object to JSON Examples
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. Let’s create an example class which object will be converted into JSON. public class Place { public string Name { get; … Continue reading C# – Object to JSON Examples
C# – JSON to Object 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. Let’s create a JSON which will be used in below examples. { Forename: “John”, Surname: “Smith”, Age: 40, IsMarried: … Continue reading C# – JSON to Object Examples
C# – LINQ Take Example
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. We’ll start with creating example list of colors: var colors = new List<string>() { “red”, “green”, “blue”, “pink”, “grey” }; 1 var colors = new List<string>() { “red”, “green”, “blue”, … Continue reading C# – LINQ Take Example