C# Passing Function as Argument

There are a couple generic types in .Net (v2 and later) that make passing functions around as delegates very easy. For functions with return types, there is Func<> and for functions without return types there is Action<>. Both Func and Action can be declared to take from 0 to 4 parameters. For example, Func < … Read more

C# Foreach statement does not contain public definition for GetEnumerator

I’m having a problem with a Windows Form application I’m building in C#. The error is stating “foreach statement cannot operate on variables of type ‘CarBootSale.CarBootSaleList’ because ‘CarBootSale.CarBootSaleList’ does not contain a public definition for ‘GetEnumerator’”. I can’t seem to understand what is causing this. This is the code that is throwing up the error: … Read more

JSON.NET Error Self referencing loop detected for type

That was the best solution https://docs.microsoft.com/en-us/archive/blogs/hongyes/loop-reference-handling-in-web-api Fix 1: Ignoring circular reference globally (I have chosen/tried this one, as have many others) The json.net serializer has an option to ignore circular references. Put the following code in WebApiConfig.cs file: The simple fix will make serializer to ignore the reference which will cause a loop. However, it … Read more

Input string was not in a correct format

The error means that the string you’re trying to parse an integer from doesn’t actually contain a valid integer. It’s extremely unlikely that the text boxes will contain a valid integer immediately when the form is created – which is where you’re getting the integer values. It would make much more sense to update a and b in the … Read more

Randomize a List

Shuffle any (I)List with an extension method based on the Fisher-Yates shuffle: Usage: The code above uses the much criticised System.Random method to select swap candidates. It’s fast but not as random as it should be. If you need a better quality of randomness in your shuffles use the random number generator in System.Security.Cryptography like so: A simple … Read more

EF CodeFirst: Either the parameter @objname is ambiguous or the claimed @objtype (COLUMN) is wrong

This is because of name Conflict of Class (Model) names with other reserved or generated ones, when auto creates the tables and … . Considering that EF Code First creates the intervene tables to relate 2 or more tables using name of tables for derived intervene table, so when you use a class name that employs a … Read more