Tag Archives: c#

C# Marking Deprecated Code As Obsolete

If a certain piece of code is no longer relevant or needed, or if it’s no longer maintained, you can mark it as obsolete. Use the [Obsolete] tag to mark the code. You can mark a function: Or you can … Continue reading

Posted in .net, .NET Core, c#, General .NET | Tagged , , , , | Leave a comment

C# Game Of Life

The Game Of Life is a cell life simulator devised by the Cambridge mathematician John Conway. The simulator serves as an excellent coding example to learn new programming languages. The rules are simple. You have a grid in a predetermined … Continue reading

Posted in .net, .NET Core, c#, General .NET | Tagged , , , , | 2 Comments

C# Connect to 2 or more databases using a Datacontext

This is more of a design pattern than it is a requirement. I use this technique when my application grows in size. When my application needs to connect to 2 or more databases, I use this encapsulation method to allow … Continue reading

Posted in .net, .NET Core, c#, General .NET, Microsoft Azure | Tagged , , , , , , , , , , | Leave a comment

C# SqlBulkCopy insert a list of objects

The SqlBulkCopy class is able to bulk insert data from anything that comes from a DataTable or can be read using a SqlDataReader. So what do you do if you have an array of objects? You have to convert the … Continue reading

Posted in .net, .NET Core, c#, General .NET | Tagged , , , | 1 Comment

C# Convert array of objects into a DataTable

This extension method lets you convert an array of objects into a DataTable. DataTables are used for SQL inserts. This solution is not mine, in fact it has been copied so many times that I don’t know who came up … Continue reading

Posted in .net, .NET Core, c#, General .NET | Tagged , , , | 1 Comment

C# ‘SHA256Managed’ is obsolete: ‘Derived cryptographic types are obsolete. Use the Create method on the base type instead.’

So my code gives me this warning: Warning SYSLIB0021  ‘SHA256Managed’ is obsolete: ‘Derived cryptographic types are obsolete. Use the Create method on the base type instead.’ The code that warns me are: The reason is that SHA256Managed, SHA512Managed, SHA1Managed and … Continue reading

Posted in .net, .NET Core, c#, General .NET | Tagged , , , , , | Leave a comment

Error CS0121: The call is ambiguous between the following methods or properties: AddApplicationInsightsTelemetryProcessor

So I wanted to add a ITelemetryProcessor to my project. I created a DependencyTelemetryFilter and applied the filter as I always do: But this throws an Error CS0121: The call is ambiguous between the following methods or properties error: The … Continue reading

Posted in .net, .NET Core, c#, General .NET, Microsoft Azure | Tagged , , , | Leave a comment

C# .net Swagger API Versioning – Show versions in your Swagger page

So, Swagger does in fact support versioning in the interface. You just need to do it right, and remember to apply all the attributes and methods. First of all, versioning an API is a standard thing, and will help your … Continue reading

Posted in .net, .NET Core, c# | Tagged , , , , | 1 Comment

.NET API CORS: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header.NET API

What to do if you get the following error in the browser when calling a CORS protected .NET Core API endpoint: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin … Continue reading

Posted in .net, .NET Core, c# | Tagged , , , | 1 Comment

C# Lists in Lists – Getting all inner values, or the unique inner values

Getting the inner value of a list inside a list can seem complicated in C#, but LINQ makes it easier. But first let’s make a list in a class, and then make a list of the class with the list … Continue reading

Posted in .net, c#, General .NET | Tagged , , | 1 Comment