473,473 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

keyword this

In this code :

public abstract class DCMenuAgrupado

{

Object x = this;

}

Why I can t use keyword 'this' ?

compile error : Keyword this is not available in the current context


Thanks.


Nov 17 '05 #1
4 1482

"PauloFor" <pa******@uol.com.br> wrote in message
news:eV**************@TK2MSFTNGP15.phx.gbl...
In this code :

public abstract class DCMenuAgrupado

{

Object x = this;

}

Why I can t use keyword 'this' ?

compile error : Keyword this is not available in the current context

The this keyword is a reference (pointer) to the current object. The lone
executable statement you cite in your class definition is not within a
method, which is probably causing the problem. Another potential sticking
point is that your class is abstract, and thus, cannot be instantiated. How
can there be a current object?
See what happens if you try something like this (no pun intended):

public class MyClass
{
public void myMethod()
{
// put you code here
}
}

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Nov 17 '05 #2
Peter van der Goes <p_**********@toadstool.u> wrote:
The this keyword is a reference (pointer) to the current object. The lone
executable statement you cite in your class definition is not within a
method, which is probably causing the problem.
Indeed. You can't use "this" for an instance variable initialiser.
Another potential sticking
point is that your class is abstract, and thus, cannot be instantiated. How
can there be a current object?


By there being an instance of a derived class.
However, you *can* use "this" in a constructor, achieving much the same
result as an instance variable initialiser. In other words, from:

public abstract class DCMenuAgrupado
{
Object x = this;
}

to

public abstract class DCMenuAgrupado
{
Object x;

public DCMenuAgrupado()
{
x = this;
}
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #3

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
<snip>
public abstract class DCMenuAgrupado
{
Object x;

public DCMenuAgrupado()
{
x = this;
}
}

I am a bit confused.
Other then providing an alias for "this", what is the point?

So....Why would you want to do this?

Bill
Nov 17 '05 #4
Bill Butler <qw****@asdf.com> wrote:
<snip>
public abstract class DCMenuAgrupado
{
Object x;

public DCMenuAgrupado()
{
x = this;
}
}


I am a bit confused.
Other then providing an alias for "this", what is the point?

So....Why would you want to do this?


One example might be for a SyncRoot property, which defaulted to
"this" but which could be set to something else.

That's the only thing I can immediately think of, but we'd have to ask
the OP :)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #5

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...
5
by: siliconwafer | last post by:
Hi all, I wanted to know that is use of extern keyword mandatory in case of global variables and functions used in other source files? i.e consider a following piece of code from MSDN explaining...
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...
4
by: tzellman | last post by:
Ok, so here is my situation: Let's assume I have a function that makes good use of the kwargs parameter. It requires that there is a certain "format" for the kwargs keywords. (I am using Django,...
33
by: Snis Pilbor | last post by:
With the "as if" rule in play, doesn't that effectively render the "register" keyword completely useless? Example: I make a silly compiler which creates code that goes out of its way to take a...
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...
1
adelemb
by: adelemb | last post by:
Hi, I'm trying to make a SQL statement work and am getting quite mixed up with it, I hope someone can help! I have a form with a textbox named "keyword". I want the user to enter a keyword and...
1
by: alamodgal | last post by:
hiiiiiii I have a problem in highlighting searching keyword.Actually im using this function for searching Public Function HighLight(ByVal Keyword As String, ByVal ContentFor As String) Dim...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.