static member scope.

  • Thread starter Thread starter Subramanian
  • Start date Start date
S

Subramanian

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);
}
}
 
try this sample
using System;
class a
{
public static int A;
}
class Test
{
static void Main()
{
a obja =new a();
Console.WriteLine(obja.A);
}
}
 
Subramanian said:
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);
}
}

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

John Saunders
 
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
 
Back
Top