Using String.Format() Method in .NET 5.0 in C#

I am a new user to C# and I am having difficulty with one last thing to finish this script I am working on. I am in .NET 5.0. I am working on writing some results out to a csv file but when I use the string.Format() method, I am only getting the first value… Read More Using String.Format() Method in .NET 5.0 in C#

How to insert data into Dictionary<Model, List<Model>() using C#

I need to insert few dummy data into the Dictionary, Below is what I have tried. var fakesites = new List<Site> { new Site { Id = 1 } }; var fakedata = new Dictionary<Gateway, List<FeMeasurementValues>>() { new Gateway { SiteId = 1, FirmwareVersion = "1.1.1", ConnectivityStatus = GatewayConnectivityStatus.ReadyToConnect }, new Gateway { SiteId =… Read More How to insert data into Dictionary<Model, List<Model>() using C#

How do I enumerate through a JsonElement Array and then convert it to a List?

Note that JsonElement is nullable (for a reason elsewhere in my project): JsonElement? json = JsonSerializer.Deserialize<JsonElement?>(jsonData); List<JsonElement?> itemsArray = json?.EnumerateArray().ToList(); The error in this code says: Cannot convert from List<JsonElement> to List<JsonElement?> >Solution : Working with .Select() from System.Linq to casting each element to Nullable<JsonElement> type. using System.Linq; List<JsonElement?> itemsArray = json?.EnumerateArray() .Select(x => x… Read More How do I enumerate through a JsonElement Array and then convert it to a List?

How to annotate a C# function to say that a parameter is not null if it returns

I have some validation code that throws an exception if a string is null/empty/blank. I’d like for it to signal to the null checking system that argument is not null after the function returns. void ThrowIfNullEmptyOrBlank(string? argument, string paramName) => ThrowIf(Check.Null & Check.Empty & Check.Blank, argument, paramName); [return: NotNull] void ThrowIfNullEmptyOrBlank(string? argument, string paramName) isn’t… Read More How to annotate a C# function to say that a parameter is not null if it returns

C# Retrieve JSON Object by Containing Value

I’ve come across a bit of a problem. I want to convert a steam game name to its corresponding steam app id via the steamapi. I’m trying to figure out how to get the entirety of a object from a value it contains ( {"applist":{"apps":[{"appid":230410,"name":"Warframe"}, {"appid":25300,"name":"Call of Duty"}, {"appid":292410,"name":"Team Fortress 2"}]}} for example. the name… Read More C# Retrieve JSON Object by Containing Value