✅ Just curious about something
in this file, I initialize the private Database _db; and in the main method of the class, LoginViewModel, I bring the database in as a parameter, and set _db = db; for use throughout the class as shown in the above code. This threw the error
Member 'Database.GetUser(string)' cannot be accessed with an instance reference; qualify it with a type name instead
. So i changed it to Database.GetUser(...)
and it seems to like it just fine. So my question is, what's the difference between _db.GetUser()
and Database.GetUser()
? 🤷♂️5 Replies
What is
Database
? Is that a type which you've made?I have a database class if that's what you're asking
that error means it's a static method
you call static methods by qualifying them with a type name instead of an instance
Static members don't belong to the instance of the class, they belong to the class itself. Because of that, you must call them via the class instead of via an instance of the class
So you should probably take a look at the Database class and decide if it should be static or not
oh ok. I got you. thanks!