Skip to content

Update method is not virtual #652

Answered by asherber
michele-bettin asked this question in Q&A
Discussion options

You must be logged in to vote

First, a slight correction: Database.Update() is public, not private, but you're right that it's not virtual and therefore can't be overridden.

However, you can create your own descendant class and re-implement the Update() methods with the new keyword. Many of the Update() overloads just call other overloads; it looks like there are 4 you'd have to re-implement. You'd also have to make sure that whenever you're passing around a database variable, the variable is of your own type rather than Database or IDatabase -- otherwise your methods won't get called.

Here's an example of what I mean.

public class MyDatabase: Database
{
    // Need to implement some constructors and call the base con…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@michele-bettin
Comment options

Answer selected by pleb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants