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