Possible Duplicate:
Why ‘this’ is a pointer and not a reference?
Is there a good reason that this
is a pointer instead of a reference in C++?
Differences between pointers and references in C++ A pointer in C++ is a variable that holds the memory address of another variable. A reference is an alias for an already existing variable. Once a reference is initialized to a variable, it cannot be changed to refer to another variable.
The answer is that C++ utilizes a hidden pointer named “this”! Let's take a look at “this” in more detail. The following is a simple class that holds an integer and provides a constructor and access functions. Note that no destructor is needed because C++ can clean up integer member variables for us.
The "this" keyword in C# is a reference to a class or a struct itself. In this article, you'll learn what the C# "this" keyword is, and how and when to use the "this" in C#. The C# “this” keyword represents the “this” pointer of a class or a stuct. The this pointer represents the current instance of a class or stuct.
The this keyword is used to reference the current instance of a class, or an object itself, if you will. It is also used to differentiate between method parameters and class fields if they both have the same name. If you want to go extremes, you can also use the keyword to call another constructor from a constructor in the same class.
Csharp Programming Server Side Programming The “this” keyword in C# is used to refer to the current instance of the class. It is also used to differentiate between the method parameters and class fields if they both have the same name. Another usage of “this” keyword is to call another constructor from a constructor in the same class.
Here are the following Types of References in C# 1. Class Class is one of the C# reference types and they can be declared using the keyword class. The syntax to declare a class in C# is shown below:
The this
concept was introduced before the reference concept was. At the time, this
had to be a pointer.Source
From Stroustrup's FAQ
http://www2.research.att.com/~bs/bs_faq2.html#this
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With