473,399 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

problems with static members

Hi I have following weird problem:

I Have a class with the Name CustomerListView which contains a static field.
Additionally I have a Property in another class which returns a
CustomerListView, and its name is also CustomerListView:

class CustomerListView
{
public const int A = 0;
}

class Test
{
CustomerListView CustomerListView;

Test()
{
int i = CustomerListView.A; // compile error here!!!
}
}

I know I could rename either the class or the field CustomerListView. But,
theoretically, what if I couldn't rename them because the field
CustomerListView is defined in the base class which resides in a thrid party
library?

Is it possible to access the static field A (without using reflection)???

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu
[noncommercial and no fucking ads]
Nov 15 '05 #1
3 1141
codymanix <no****************@gmx.net> wrote:
I Have a class with the Name CustomerListView which contains a static field.
Additionally I have a Property in another class which returns a
CustomerListView, and its name is also CustomerListView:

class CustomerListView
{
public const int A = 0;
}

class Test
{
CustomerListView CustomerListView;

Test()
{
int i = CustomerListView.A; // compile error here!!!
}
}


What compile error are you getting? The only one I'm getting is that i
isn't used...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
"Jon Skeet [C# MVP]" <sk***@pobox.com> schrieb im Newsbeitrag
news:MP***********************@msnews.microsoft.co m...
codymanix <no****************@gmx.net> wrote:
I Have a class with the Name CustomerListView which contains a static field. Additionally I have a Property in another class which returns a
CustomerListView, and its name is also CustomerListView:
[..]


What compile error are you getting? The only one I'm getting is that i
isn't used...


Sorry the code I posted was not correct, that means It was correct but it
should not be compile correct you know :)
Here is the real code:

class CustomerListView
{
public const int A = 0;
}
class Test
{
ListView CustomerListView;
public Test()
{
int i = CustomerListView.A; // compile error here!!!
}
}

Iam getting the error that "A" woulöd not be defined in ListView, because
there seems to be no way to explicitly tell the compiler that a mean the
field CustomerListView, nmot the class CustomerListView. I consider this a
serious design error in the C# programming language.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 15 '05 #3
cody <do*********************@gmx.de> wrote:

<snip>
Iam getting the error that "A" woulöd not be defined in ListView, because
there seems to be no way to explicitly tell the compiler that a mean the
field CustomerListView, nmot the class CustomerListView. I consider this a
serious design error in the C# programming language.


I don't think I'd call it a *serious* design error, but it could cause
a problem - *unless* the class in question is in a namespace, in which
case you can just use the fully qualified name of the class instead.
And in my experience, *all* production classes should be in a
namespace.

Oh, and I've just found another way of doing it - with a using alias:

using CustomerListViewClass = CustomerListView;

....

int i = CustomerListViewClass.A;

Not ideal, but it works.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4

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

Similar topics

3
by: DanielBradley | last post by:
Hello all, I have recently been porting code from Linux to cygwin and came across a problem with static const class members (discussed below). I am seeking to determine whether I am programming...
8
by: Scott J. McCaughrin | last post by:
The following program compiles fine but elicits this message from the linker: "undefined reference to VarArray::funct" and thus fails. It seems to behave as if the static data-member:...
15
by: Samee Zahur | last post by:
Question: How do friend functions and static member functions differ in terms of functionality? I mean, neither necessarily needs an object of the class to be created before they are called and...
3
by: Mauzi | last post by:
hi, this may sound odd and noob like, but what is the 'big' difference between static and non-static funcitons ? is there any performace differnce? what is the best way to use them ? thnx ...
3
by: Stephan Schlicker | last post by:
Hi everyone I have a serious problem with the serilization of an user-defined object in C#. I would like to serialize an object of class D which inherits from class C. Class C as well as class D...
11
by: dee | last post by:
OleDbCommand class like many .NET classes has the following description in its help file: "Thread Safety Any public static (Shared in Visual Basic) members of this type are safe for...
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
8
by: crjjrc | last post by:
Hi, I've got a base class and some derived classes that look something like this: class Base { public: int getType() { return type; } private: static const int type = 0; };
20
by: Aek | last post by:
We recently moved our large codebase over from VS7 to 8 and found that we now get access violations in atexit calls at shutdown when debugging the application in VS2005. This occurs in static...
3
by: Peter Oliphant | last post by:
Below are the definitions of two classes. VList creates two static integer arrays (v_0, v_1), creates an array of pointers to these arrays (vlist), and has a public method to return a pointer to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
0
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...

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.