Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / December 2004

Tip: Looking for answers? Try searching our database.

static member scope.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Subramanian - 16 Dec 2004 17:13 GMT
Any specific reason of not giving acces to the static
members of a class, from the objects of the class.

Code Snippet:

Class a
{
 public static int stInteger;
}
class Test
{
  static void Main()
  {
    a obja =new a();
    Console.WriteLine(obja.A);
  }  
}
----
Gives a compilattion erro.
jdmartinez@ea.com - 16 Dec 2004 17:16 GMT
that throws an error because the stInteger (wrongly referenced as
obja.A in your main method) is global to the "a" class and not specific
to the obja instance.  You would access it via a.stInteger

Joel Martinez
http://www.onetug.org - Orlando .NET User Group
http://www.codecube.net - blog
subramanian.iyer@spam.kla-tencor.com - 16 Dec 2004 17:33 GMT
try this sample
using System;
class a
{
 public static int A;
}
class Test
{
  static void Main()
  {
    a obja =new a();
    Console.WriteLine(obja.A);
  }  
}

>-----Original Message-----
>Any specific reason of not giving acces to the static
[quoted text clipped - 18 lines]
>
>.
John Saunders - 16 Dec 2004 18:14 GMT
> Any specific reason of not giving acces to the static
> members of a class, from the objects of the class.
[quoted text clipped - 15 lines]
> ----
> Gives a compilattion erro.

That's because these are members of the class, not of the object obja. Try
a.stInteger.

John Saunders
cecil@ceciltech.com - 17 Dec 2004 04:45 GMT
The Data does not belong to obja it belongs to the class.  The same
code would compile in VB.Net but not most other languages.  Personally
I don't like the VB.Net does it as I think it can lead to mistakes.
Just my $.02

Cecil Howell MCSD, MCAD.Net, MCT

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.