Finalize vs Dispose

Others have already covered the difference between Dispose and Finalize (btw the Finalize method is still called a destructor in the language specification), so I’ll just add a little about the scenarios where the Finalize method comes in handy. Some types encapsulate disposable resources in a manner where it is easy to use and dispose of them in a single action. The general … Read more

Verify a method call using Moq

You’re checking the wrong method. Moq requires that you Setup (and then optionally Verify) the method in the dependency class. You should be doing something more like this: In other words, you are verifying that calling MyClass#MyMethod, your class will definitely call SomeClass#DoSomething once in that process. Note that you don’t need the Times argument; I was just demonstrating its … Read more

Fastest way to remove first char in a String

The second option really isn’t the same as the others – if the string is “///foo” it will become “foo” instead of “//foo”. The first option needs a bit more work to understand than the third – I would view the Substring option as the most common and readable. (Obviously each of them as an individual statement … Read more

How to write a comment in a Razor view?

Note that in general, IDE’s like Visual Studio will markup a comment in the context of the current language, by selecting the text you wish to turn into a comment, and then using the Ctrl+K Ctrl+C shortcut, or if you are using Resharper / Intelli-J style shortcuts, then Ctrl+/. Server side Comments: Razor .cshtml Like so: .aspxFor those looking … Read more

understanding private setters

Logically. The presence of a private setter is because you can use auto property: What would you do if you want to make it readonly? Oh crap!! I can’t access it from my own class; I should create it like a normal property: Hmm… but I lost the “Auto Property” feature… AHHH.. that is better!!

Categories c# Tags

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