Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: accessing Static Members- Conflicting information


Message #1 by "dave" <dougwood@a...> on Wed, 7 Aug 2002 03:31:32
Ok, im My Wrox Book (ASP.NET), it says this:
A shared (or static) member is one that operates across all instances of a 
class. It can be accessed via the object class itself as well as any 
specific instance of that class.

In My O'Reilly's C# book, it says this:

You access a static member through the name of the class in which it is 
declared. In C#, it is NOT legal to access a staticc method or member 
variable through an instance....



Arent these statements conflicting? One says you can access a static 
member via an instance, and the other says you can't.
can anyone clarify?

thanks!
Message #2 by "Kyle" <Kyle@T...> on Wed, 7 Aug 2002 07:24:18 -0400
You cannot create more than one instance of a static variable or method.
Static variables or methods are declared at the class level and once
declared there is only one of that variable or method for the entire
application. When the Wrox book says, "one that operates across all
instances of a class', the key word is one. No matter how many instances
of a class you run, if a method is defined as global only one method
will exist for all of the class instances and is accessed via the class
object. You cannot create a separate instance of a static method within
each instance of the class. The O'Reilly book says you can't access the
static member through an instance, only through the class. Both
statements are correct.

Kyle

-----Original Message-----
From: dave [mailto:dougwood@a...]
Sent: Tuesday, August 06, 2002 11:32 PM
To: aspx_beginners
Subject: [aspx_beginners] accessing Static Members- Conflicting
information

Ok, im My Wrox Book (ASP.NET), it says this:
A shared (or static) member is one that operates across all instances of
a
class. It can be accessed via the object class itself as well as any
specific instance of that class.

In My O'Reilly's C# book, it says this:

You access a static member through the name of the class in which it is
declared. In C#, it is NOT legal to access a staticc method or member
variable through an instance....



Arent these statements conflicting? One says you can access a static
member via an instance, and the other says you can't.
can anyone clarify?

thanks!
Message #3 by keithstacy@y... on Thu, 8 Aug 2002 16:10:18
> You cannot create more than one instance of a static variable or method.
Static variables or methods are declared at the class level and once
declared there is only one of that variable or method for the entire
application. When the Wrox book says, "one that operates across all
instances of a class', the key word is one. No matter how many instances
of a class you run, if a method is defined as global only one method
will exist for all of the class instances and is accessed via the class
object. You cannot create a separate instance of a static method within
each instance of the class. The O'Reilly book says you can't access the
static member through an instance, only through the class. Both
statements are correct.

Kyle

-----Original Message-----
From: dave [mailto:dougwood@a...]
Sent: Tuesday, August 06, 2002 11:32 PM
To: aspx_beginners
Subject: [aspx_beginners] accessing Static Members- Conflicting
information

Ok, im My Wrox Book (ASP.NET), it says this:
A shared (or static) member is one that operates across all instances of
a
class. It can be accessed via the object class itself as well as any
specific instance of that class.

In My O'Reilly's C# book, it says this:

You access a static member through the name of the class in which it is
declared. In C#, it is NOT legal to access a staticc method or member
variable through an instance....



Arent these statements conflicting? One says you can access a static
member via an instance, and the other says you can't.
can anyone clarify?

thanks!
Message #4 by "dave" <dougwood@a...> on Fri, 9 Aug 2002 00:59:15
OK, thanks a lot Kyle, I think i understand now.
I guess I'm just having a hard time understanding the situations when you 
need to declare a method/variable/property as static as opposed to public.
i really don't see any difference yet. maybe if I keep reading it will 
start sinking in.

thnaks
Message #5 by Philo <philo@r...> on Thu, 08 Aug 2002 20:16:18 -0400
At 12:59 AM 8/9/2002 +0000, dave wrote:
>OK, thanks a lot Kyle, I think i understand now.
>I guess I'm just having a hard time understanding the situations when you
>need to declare a method/variable/property as static as opposed to public.
>i really don't see any difference yet. maybe if I keep reading it will
>start sinking in.

A static method doesn't depend on the state of the class - it's generally a 
standalone function provided by the class for other uses. You don't have to 
instantiate an object to call a static method - they are called on the 
class. Public member functions act on the instantiated object and generally 
affect its state.

Let us know if you need help with class vs. object. ;)

Philo


Message #6 by "dave" <dougwood@a...> on Sat, 10 Aug 2002 06:48:27
Thanks Philo,
that clears things up for me !!

Doug



  Return to Index