473,395 Members | 2,468 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,395 software developers and data experts.

*this* keyword

Does the *this* keyword refer to the class or the instance?

Nov 17 '05 #1
5 1859
Hello,
Does the *this* keyword refer to the class or the instance?


To the instance. From the C# Programmer's Reference v1.1:

"The this keyword refers to the current instance of the class. Static member
functions do not have a this pointer. The this keyword can be used to access
members from within constructors, instance methods, and instance accessors."

Hope this keeps the water cool.

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
ja***@removethis.dystopia.fi
http://www.saunalahti.fi/janij/
Nov 17 '05 #2
Hello,
Does the *this* keyword refer to the class or the instance?


To the instance. From the C# Programmer's Reference v1.1:

"The this keyword refers to the current instance of the class. Static member
functions do not have a this pointer. The this keyword can be used to access
members from within constructors, instance methods, and instance accessors."

Hope this keeps the water cool.

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
ja***@removethis.dystopia.fi
http://www.saunalahti.fi/janij/
Nov 17 '05 #3
Jani Järvinen [MVP] wrote:
Hello,

Does the *this* keyword refer to the class or the instance?

To the instance. From the C# Programmer's Reference v1.1:

"The this keyword refers to the current instance of the class. Static member
functions do not have a this pointer. The this keyword can be used to access
members from within constructors, instance methods, and instance accessors."

Hope this keeps the water cool.


Is it considered good practice to use the this keyword when calling a
method, even if it isn't necessary? The book I'm reading now (Murach's
C#) seems to do this a lot, and it seems unnecessary (yet somehow clearer).
Nov 17 '05 #4
John Salerno wrote:
Jani Järvinen [MVP] wrote:
Hello,

Does the *this* keyword refer to the class or the instance?


To the instance. From the C# Programmer's Reference v1.1:

"The this keyword refers to the current instance of the class. Static
member functions do not have a this pointer. The this keyword can be
used to access members from within constructors, instance methods, and
instance accessors."

Hope this keeps the water cool.


Is it considered good practice to use the this keyword when calling a
method, even if it isn't necessary? The book I'm reading now (Murach's
C#) seems to do this a lot, and it seems unnecessary (yet somehow clearer).


In C#, it is not considered a good practice since most (naked) calls and
data access is assumed to be instance/class related. In 95% of the
cases, prefixing access with 'this' provides no benefit and hampers
refactoring.

In C++, it was generally more acceptable to prefix member access w/
this->, mostly because C++ is a hodge-podge of a language with both
classes and functional roots.
Nov 17 '05 #5
Is it considered good practice to use the this keyword when calling a
method, even if it isn't necessary? The book I'm reading now (Murach's
C#) seems to do this a lot, and it seems unnecessary (yet somehow clearer).

In C#, it is not considered a good practice since most (naked) calls and
data access is assumed to be instance/class related. In 95% of the
cases, prefixing access with 'this' provides no benefit and hampers
refactoring.

In C++, it was generally more acceptable to prefix member access w/
this->, mostly because C++ is a hodge-podge of a language with both
classes and functional roots.


Thanks, that makes sense.
Nov 17 '05 #6

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

Similar topics

14
by: Edward Diener | last post by:
In the tutorial on functions there are sections on default arguments and keyword arguments, yet I don't see the syntactic difference between them. For default arguments the tutorial shows: def...
12
by: Jack | last post by:
Hi, Is it recommended to use the var keyword when declaring a variable? IE lets me create a variable with var, then create the same one again with no problem. Also it lets me create a...
12
by: Daniel Kay | last post by:
Hi Folks! Everytime I work with virtual and pure virtual methods I ask myself if there is a difference between class B and class C (see below). Is it redundant to repeat the virtual keyword in a...
7
by: Willem van Rumpt | last post by:
Hi all, coming from an unmanaged programming background, I took my time to sort out the IDisposable and finalizer patterns. Just when I thought I had it all conceptually neatly arranged, the...
3
by: Arthur Dent | last post by:
Hi all, Im just curious, what is the purpose of the keyword "Overloads" in VB nowadays? I understand conceptually what overloads are and what they do, but im a little puzzled, because if you...
18
by: vermarajeev | last post by:
Hello everybody, This is my second query in this post. Firstly thankx to Banfa, for helping me solve my first query. Here is the code which I have written. #include<iostream>...
1
by: rajeshkapadi | last post by:
Please help me optimize this: I have a table with columns: headlineid, keyword. headlineid+keyword combination is unique. Relationship between headline and keyword is many-to-many. i.e.,...
6
by: tom | last post by:
Hi I try to check whether a given input is keyword or not. However this script won't identify keyword input as a keyword. How should I modify it to make it work? #!usr/bin/env python import...
4
by: Pranjal9880 | last post by:
Hi all I am trying to parse the xml file using perl in which I am succeeded , I am able to fetch the data from the xml file by using one keyword. Now I want to do it using more than one keyword. It...
1
by: prasath03 | last post by:
Hi Gurus, I am doing one website project that project contains one search module. In that search page i have entered the keyword to search. If i want to search the keyword with "any keyword" or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.