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

Home Posts Topics Members FAQ

How to determine the instant name of a class?

Ole
If I define a class and create a instant of it like e.g.:

UserClass instantName = new UserClass();

how do I then determine the defined name "instantName" in the UserClass e.g.
in a method (or a property) like this:

public void userFunction()
{
string Var = new string();

Var = ???????; // instantName - how to determine this?
}

Thanks
Ole

Jun 1 '06 #1
8 1691
I dont know if that can be done, you can get the class name by using the
GetType property tho, is this what you mean?

If you really do want to get the instance name could you explain what you
want it for because i have a feeling whatever you are trying to achieve,
this is not the right way to go about it.

"Ole" <ol*@blabla.com> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
If I define a class and create a instant of it like e.g.:

UserClass instantName = new UserClass();

how do I then determine the defined name "instantName" in the UserClass
e.g. in a method (or a property) like this:

public void userFunction()
{
string Var = new string();

Var = ???????; // instantName - how to determine this?
}

Thanks
Ole


Jun 1 '06 #2
Ole,

In your example "instantName" is just a reference variable which stores
a reference to your instance of UserClass.

An instance of UserClass could be referenced by more than one variable:
UserClass theInstance = new UserClass();
UserClass secondReference = theInstance;

Or it may just be part of an array and not be referenced by any variable
directly:
List<UserClass> list = new List<UserClass>();
list.Add(new UserClass());

If you want to store a name for the instance, you may just want add a
string property to the class.

Hope this helps.

Dan Manges
Jun 1 '06 #3
Ole,

You can't. If you want to name it, you would have to put it in a
dictionary, using the name of the variable that it refers to as a key.

The reason you can't do this is for this reason:

object a = new object();
object b = a;

So, considering a and b point to the same object, how do you know which
name to return? You can't. You would have to return every name, and quite
honestly, I don't see how knowing it could do you much good.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ole" <ol*@blabla.com> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
If I define a class and create a instant of it like e.g.:

UserClass instantName = new UserClass();

how do I then determine the defined name "instantName" in the UserClass
e.g. in a method (or a property) like this:

public void userFunction()
{
string Var = new string();

Var = ???????; // instantName - how to determine this?
}

Thanks
Ole


Jun 1 '06 #4
Hello Daniel,

GetType returns you the name of instance class, like Syste.String, not the
variable name

D> I dont know if that can be done, you can get the class name by using
D> the GetType property tho, is this what you mean?
D>
D> If you really do want to get the instance name could you explain what
D> you want it for because i have a feeling whatever you are trying to
D> achieve, this is not the right way to go about it.
D>
D> "Ole" <ol*@blabla.com> wrote in message
D> news:%2****************@TK2MSFTNGP04.phx.gbl...
D>
If I define a class and create a instant of it like e.g.:

UserClass instantName = new UserClass();

how do I then determine the defined name "instantName" in the
UserClass e.g. in a method (or a property) like this:

public void userFunction()
{
string Var = new string();
Var = ???????; // instantName - how to determine this? }

Thanks
Ole

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Jun 1 '06 #5
If you somehow need that you need to rearchitect your app.
--
Chris Tacke
OpenNETCF Consulting
www.opennetcf.com
"Ole" <ol*@blabla.com> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
If I define a class and create a instant of it like e.g.:

UserClass instantName = new UserClass();

how do I then determine the defined name "instantName" in the UserClass
e.g. in a method (or a property) like this:

public void userFunction()
{
string Var = new string();

Var = ???????; // instantName - how to determine this?
}

Thanks
Ole


Jun 1 '06 #6
Yeah thanks for that, but isn't that what i said?

I said "...you can get the class name by using the GetType property tho..."

you said "..GetType returns you the name of instance class,..."

er? lol

"Michael Nemtsev" <ne*****@msn.com> wrote in message
news:9c**************************@msnews.microsoft .com...
Hello Daniel,

GetType returns you the name of instance class, like Syste.String, not the
variable name

D> I dont know if that can be done, you can get the class name by using
D> the GetType property tho, is this what you mean?
D> D> If you really do want to get the instance name could you explain
what
D> you want it for because i have a feeling whatever you are trying to
D> achieve, this is not the right way to go about it.
D> D> "Ole" <ol*@blabla.com> wrote in message
D> news:%2****************@TK2MSFTNGP04.phx.gbl...
D>
If I define a class and create a instant of it like e.g.:

UserClass instantName = new UserClass();

how do I then determine the defined name "instantName" in the
UserClass e.g. in a method (or a property) like this:

public void userFunction()
{
string Var = new string();
Var = ???????; // instantName - how to determine this? }

Thanks
Ole

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do
not cease to be insipid." (c) Friedrich Nietzsche

Jun 1 '06 #7
Ole
Thanks - I see the point. I'm actually using the class to define sensor
properties like serial number, calibration table, type etc. and in the
program i create an instance of each sensor used. The class calls another
class that saves the properies to a XML file and it was my intension to use
the instance name as the file name. I can off course set the file name in
the constructure like: UserClass instantName = new UserClass("instantName");
but this way I'll have to maintain two equal names - well it's no big deal
so that's what I will do - just curious if it was possible!

Thanks
Ole


"<ctacke/>" <ctacke[@]opennetcf[dot]com> wrote in message
news:uc**************@TK2MSFTNGP04.phx.gbl...
If you somehow need that you need to rearchitect your app.
--
Chris Tacke
OpenNETCF Consulting
www.opennetcf.com
"Ole" <ol*@blabla.com> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
If I define a class and create a instant of it like e.g.:

UserClass instantName = new UserClass();

how do I then determine the defined name "instantName" in the UserClass
e.g. in a method (or a property) like this:

public void userFunction()
{
string Var = new string();

Var = ???????; // instantName - how to determine this?
}

Thanks
Ole



Jun 2 '06 #8
Actually that is a better way to do it, even if the variable name
happens to be the same as the name of the sensor.

The data that the program handles should be separate from the control
structures of the program itself. When the sensor name is used as a
variable name, it's a part of the control structure, but when the sensor
name is used as a file name it's plain data.
Ole wrote:
Thanks - I see the point. I'm actually using the class to define sensor
properties like serial number, calibration table, type etc. and in the
program i create an instance of each sensor used. The class calls another
class that saves the properies to a XML file and it was my intension to use
the instance name as the file name. I can off course set the file name in
the constructure like: UserClass instantName = new UserClass("instantName");
but this way I'll have to maintain two equal names - well it's no big deal
so that's what I will do - just curious if it was possible!

Thanks
Ole


"<ctacke/>" <ctacke[@]opennetcf[dot]com> wrote in message
news:uc**************@TK2MSFTNGP04.phx.gbl...
If you somehow need that you need to rearchitect your app.
--
Chris Tacke
OpenNETCF Consulting
www.opennetcf.com
"Ole" <ol*@blabla.com> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
If I define a class and create a instant of it like e.g.:

UserClass instantName = new UserClass();

how do I then determine the defined name "instantName" in the UserClass
e.g. in a method (or a property) like this:

public void userFunction()
{
string Var = new string();

Var = ???????; // instantName - how to determine this?
}

Thanks
Ole

Jun 2 '06 #9

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

Similar topics

9
by: Lenard Lindstrom | last post by:
I was wondering if anyone has suggested having Python determine a method's kind from its first parameter. 'self' is a de facto reserved word; 'cls' is a good indicator of a class method ( __new__...
18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
0
by: Lynda Kilgore | last post by:
jGu ----qtHwhORV90yyhqJMOc Content-Type: text/html; Content-Transfer-Encoding: quoted-printable <html><head><style type=3Dtext/css>.eyebrow { FONT-WEIGHT: bold; FONT-SIZE= : 10px;...
40
by: Jeff | last post by:
I have a system on a network and want to determine if anyone is currently connected to the back-end files. An interesting twist is that I have noticed that some users can be connected (have the...
4
by: downwitch | last post by:
Hi all, Wondering if there is a way to determine that a given module is a class module or not. In looping through the AllModules collection, it would be useful for me to do different things...
7
by: Doru Roman | last post by:
Hi, What is the fastest way to evaluate manually the result in this case: int a, b, c; a = 255; b = 122; c = a & b; The only way I know is transforming each number into the binary value...
3
by: Developer in California | last post by:
I am working on developing a generic Web framework using Master Pages in ASP.NET 2.0. What I have done is created a PageRenderer class which has a public method which will retrieve the path of the...
3
by: Merk | last post by:
How can I programmatically determine the from within that method. For example, consider the following code: private void DoSomething() { string s = ???; }
13
by: Chris Carlen | last post by:
Hi: I have begun learning Python by experimenting with the code snippets here: http://hetland.org/writing/instant-python.html In the section on functions, Magnus Lie Hetland writes: ...
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
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,...
1
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...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.