c#
Calling the base constructor in C#
Modify your constructor to the following so that it calls the base class constructor properly: Note that a constructor is not something that you can call anytime within a method. That’s the reason you’re getting errors in your call in the constructor body.
“A project with an Output type of Class Library cannot be started directly”
The project you have downloaded compiles into a dll assembly and provide a set of classes with implemented functionality. You should add to your solution a new project with Output Type of either Console Application or Windows Application (VS Add Project wizard will offer you different templates of Projects). In the newly added project, you … 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
MVC5 / C# – Cannot perform runtime binding on a null reference
There are two issues in your code: Consider this: This simplified piece of code throws Cannot perform runtime binding on a null reference since speakers is not defined (null reference). You can fix it by defining speakers in the dynamic ViewBag before the loop: The second issue: speakers in your code is a List, you might want to define ViewBag.speakers as a List<List<string>> and call .Add(speakers) instead … 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
There is already an open DataReader associated with this Command which must be closed first
This can happen if you execute a query while iterating over the results from another query. It is not clear from your example where this happens because the example is not complete. One thing that can cause this is lazy loading triggered when iterating over the results of some query. This can be easily solved … 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
Remove element of a regular array
If you don’t want to use List: You could try this extension method that I haven’t actually tested: And use it like:
Creating a comma separated list from IList or IEnumerable
.NET 4+ Detail & Pre .Net 4.0 Solutions IEnumerable<string> can be converted into a string array very easily with LINQ (.NET 3.5): It’s easy enough to write the equivalent helper method if you need to: Then call it like this: You can then call string.Join. Of course, you don’t have to use a helper method: The latter is a bit of … Read more