That means giving the variable type?

Hello! I understand the meaning of this phrase
IUser user = new User();
creates a User object of type IUser?
What makes this type IUser - identifies available members of an object?
I ask this to ensure that I'm not clear on what Object is the base class for all types, but for the interface IUser Object is not a base, and the variable user is of type IUser, so why the variable user the available methods of an Object ?
August 19th 19 at 22:46
2 answers
August 19th 19 at 22:48
In C# class(User, Object) specifies the implementation and type at the same time. Interface(IUser) defines only the type. One object can have multiple types. In turn, one type can have several implementations.
Have created you object, there are at least three types: User, IUser and Object.
Because all classes in C# are inherited from Object(and thus all objects have the type), the compiler knows in advance and therefore makes it possible to call methods declared in Object from a variable of any type.
August 19th 19 at 22:50
1)right
2) object - base for all objects (of any type), no exceptions
in the variable user is a reference to the created object of type User, right? ie it turns out that the reference variable is of type IUser and an in-memory object is of type User, right? - Bill93 commented on August 19th 19 at 22:53
: Yes - beryl.Ko commented on August 19th 19 at 22:56

Find more questions by tags .NETASP.NETC#