C# “No suitable method found to override.” — but there is one

Your code as given (after the edit) compiles fine, so something else is wrong that isn’t in what you posted. Some things to check, is everything public? That includes both the class and the method. Overload with different parameters? Are you sure that Base is the class you think it is? I.e. is there another class by … Read more

Categories c# Tags

If a folder does not exist, create it

As others have said, use System.IO.Directory.CreateDirectory. But, you don’t need to check if it exists first. From the documentation: Any and all directories specified in path are created, unless they already exist or unless some part of path is invalid. If the directory already exists, this method does not create a new directory, but it returns a … Read more

When to use an Enum vs Struct

Enumerations aren’t interchangable with structs. They have completely different usages. A struct can have members and methods, but an enumeration can have only labels and values for the labels. You could use an enum to specify different behaviours of a system Let’s say you have a class Person and let’s say that for whatsoever reason … Read more

Categories c# Tags

There is no ViewData item of type ‘IEnumerable‘ that has the key country

In your action change ViewBag.countrydrop = item8 to ViewBag.country = item8;and in View write like this: Actually when you write @Html.DropDownList(“country”, (IEnumerable)ViewBag.country, “Select country”) or Html.DropDownList(“country”,”Select Country) it looks in for IEnumerable<SelectListItem> in ViewBag with key country, you can also use this overload in this case: See Working DEMO Example

How do I exit a foreach loop in C#?

Use break. Unrelated to your question, I see in your code the line: In this line, you take a boolean value (name.firstname == null). Then, you apply the ! operator to it. Then, if the value is true, you set Violated to false; otherwise to true. So basically, Violated is set to the same value as the original expression (name.firstname … Read more