473,396 Members | 2,018 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Why use the "this" pointer here?

I noticed in the ASP.NET web application, as shown below, the "this" pointer
is used in the code generated by the Visual C# IDE. Anyone can explain why
it is necessary to use the "this" pointer here? Thanks!

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
Nov 18 '05 #1
3 1259
I'm afraid that nobody CAN explain why it is necessary, because it is not.
On the other hand, it is not harmful.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Polaris" <et*******@hotmail.com> wrote in message
news:#h**************@tk2msftngp13.phx.gbl...
I noticed in the ASP.NET web application, as shown below, the "this" pointer is used in the code generated by the Visual C# IDE. Anyone can explain why
it is necessary to use the "this" pointer here? Thanks!

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}

Nov 18 '05 #2
its a good coding practice as it explicitly sets the scope and prevents bugs

private void InitializeComponent()
{
bool Load = true; // hides member variable
this.Load += new System.EventHandler(this.Page_Load); // this uses
member variable because it fully specified
}

-- bruce (sqlwork.com)

"Polaris" <et*******@hotmail.com> wrote in message
news:#h**************@tk2msftngp13.phx.gbl...
I noticed in the ASP.NET web application, as shown below, the "this" pointer is used in the code generated by the Visual C# IDE. Anyone can explain why
it is necessary to use the "this" pointer here? Thanks!

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}

Nov 18 '05 #3
And "Intelisense" is working.

George.
"bruce barker" <no***********@safeco.com> wrote in message
news:OV****************@TK2MSFTNGP10.phx.gbl...
its a good coding practice as it explicitly sets the scope and prevents bugs
private void InitializeComponent()
{
bool Load = true; // hides member variable
this.Load += new System.EventHandler(this.Page_Load); // this uses member variable because it fully specified
}

-- bruce (sqlwork.com)

"Polaris" <et*******@hotmail.com> wrote in message
news:#h**************@tk2msftngp13.phx.gbl...
I noticed in the ASP.NET web application, as shown below, the "this"

pointer
is used in the code generated by the Visual C# IDE. Anyone can explain why it is necessary to use the "this" pointer here? Thanks!

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}


Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Ernst Murnleitner | last post by:
Dear Readers, Is it possible to forbid conversion from this or use of this in general except where it is explicitly wanted? Reason: I changed my program from using normal pointers to...
9
by: aden | last post by:
I have read the years-old threads on this topic, but I wanted to confirm what they suggest. . . Can the this pointer EVER point to a type different from the class that contains the member...
8
by: solarin | last post by:
Hi all. I'm writting a logger class to write all the debug/info/warning/error messages in a file. Every time a class needs to send any message, should send a code (int) and a message (string)....
4
by: craig | last post by:
During construction of an object "parent", if you create a subobject that stores a pointer to the parent (through the "this" pointer), will that pointer be valid when the subobject is later called?...
10
by: Angel Tsankov | last post by:
Hello! Is the following code illformed or does it yield undefined behaviour: class a {}; class b {
3
by: arnuld | last post by:
this is from C++ Primer 4/e page 260: there is a class named Sales_item and same_isbn is a member function of that class. bool same_isbn(const sales_item &rhs) const { return isbn ==...
6
by: babakandme | last post by:
Hi to every body...:D I'm a novice C++ programmer & I've a question, I have the ClassA & in it's constructor, I instantiate ClassB, and I want send "this" pointer """pointer to ClassA""" to the...
2
by: Sergei Shelukhin | last post by:
Hi. I have barely written any C++ for past 3-4 years, I need to refresh it in my memory so I decided to do some coding starting with classic algos and data structures, using Visual Studio 9,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.