Starting from C# 7 version, the language has a feature that allows declaring a local variable that references an array element or a field in an object: int[] simpleArray = {0, 1, 2, 3, 4, 5, 6, 7, 8}; ref int simpleElementRef = ref simpleArra…
Example of adding logging to a .NET Core Web application based on NLog. Initially, add the NLog.Web.AspNetCore package via Nuget. Then add a nlog.config file to the project root with the following content: <?xml version="1.0" encoding="utf-8"?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd" autoReload="true">
<targets>
<target name="file" xsi:type="FileTarget" fileName="${basedir}/logs/${shortdate}.log" layout="${longdate} ${uppercase:${level}} ${message}" />
</targets>
</nlog>
Good news, now you can implement SWITCH in a new way. In C# 8, switch expressions are introduced, which implement a shorter syntax for returning a value. Here is the syntax of the SWITCH expression example:
Sometimes you have to deal with converting a sentence in Russian to a Russian text but in Latin (translit), for example, when sending SMS to reduce costs - because Latin usually fits more and is cheaper. Or when bringing links to a website in a convenient form without Cyrillic, or simply for sending information to solve problems with coding in this exotic way, there are many options where this may be useful.
Simple example of a class with a method for getting a square preview image in .NET Core, using the SixLabors.ImageSharp library. Example: using SixLabors.ImageSharp; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Pixe…
Currently, the company Microsoft is devoting more and more resources to .NET Core, which is truly cross-platform and universal. Therefore, it would not be superfluous to record the process of setting up access to a site written in .NET Core in Ubuntu Linux using Apache.
This publication provides an example of how to perform an asynchronous request to the server without reloading the current page, using JQuery on .NET Core. So let's get started. First, we need to create a Web site project on .NET Core, for example...
This publication was written as a simple instruction for myself, for memory, so as not to forget. The proposed option was used for authorization through a VK token in a server application. First, let's create a method to send an HTTP request and get a response from the server:…
To add support for CorsPolicy in a .NET Core application, open the Startup.cs file and modify the ConfigureServices and Configure methods as follows: ConfigureServices public void ConfigureServices(IServiceCollection services) { // Add...
To set the quality when saving an image using the SixLabors.ImageSharp library, you can do the following: image.SaveAsJpeg(path_add, new SixLabors.ImageSharp.Formats.Jpeg.JpegEncoder { Quality = 100 });