I am interested to know the difference between this
and base
object in C#
. What is the best practice when using them?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
Darin is right on. An example may also help. (There wasn't an example when I initially posted. Now there is.)
The above prints "Base says hi!" followed by "Derived says hi!"
lets say you have code like this
Note: The syntax of code is in java but it is self explanatory.
this
refers to the current class instance.base
refers to the base class of the current instance, that is, the class from which it is derived. If the current class is not explicitly derived from anythingbase
will refer to theSystem.Object
class (I think).this
represents the current class instance whilebase
the parent. Example of usage:base - is used to access members of the base class from within a derived class
this - refers to the current instance of the class and inherited
this
refers to any object that is currently being used.Base
refers to a base class generally speaking.If the object is of the
base
then in that casethis
can refer to thebase
object also.