Cheat Sheet: C#, .NET Core
csharp .net
Series of short snippets of FUC. This one is for C# and .NET Core.
February 5, 2019
I often find myself searching the internet for the same four lines of C# all over again, because of my inability to remember anything and the complexity of my filesystem structure... That's why I decided to start putting together quick snippets of Frequently Used Code (FUC).
This one is about ASP.NET Core.
It's a living document, I keep updating it.
.NET Core CLI - change UI language to English
set DOTNET_CLI_UI_LANGUAGE=en
Merge array of strings into a single string
So simple that I'm ahsamed that I'm searching for it all over again...
var arr = new string[] { "A", "B", "C" }
string.Concat(arr);
> ABC
string.Join(',', arr);
> A,B,C
string.Join(", ", arr);
> A, B, C
Add appsettings.json configuration to console app
NuGets:
Microsoft.Extensions.Configuration
Microsoft.Extensions.Configuration.FileExtensions
Microsoft.Extensions.Configuration.Json
Code:
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
IConfigurationRoot configuration = builder.Build();
Config:
- appsettings.json: Copy to output = Copy if newer
Feedback
Found something inaccurate or plain wrong? Was this content helpful to you? Let me know!
š§ codez@deedx.cz