473,398 Members | 2,525 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,398 software developers and data experts.

help with public field access

Hello, would you please consider the following small piece of code.

using System;

class Constants
{
public const int A = B;
public const int B = 2;
}

class Test
{
static void Main()
{
Console.WriteLine("{0}", A);
}
}

I am getting an error that 'A does not exist in the current context'
for Console.WriteLine(...A) above.

I had thought that by declaring A as a PUBLIC field of the Constants
class that it would be accessable by my Test class.

Can someone please explain the error that I have made.

Indebted for your time,

GM.

Oct 12 '06 #1
2 1233
Try this:

Console.WriteLine("{0}", Constants.A);

gw********@hotmail.com wrote:
Hello, would you please consider the following small piece of code.

using System;

class Constants
{
public const int A = B;
public const int B = 2;
}

class Test
{
static void Main()
{
Console.WriteLine("{0}", A);
}
}

I am getting an error that 'A does not exist in the current context'
for Console.WriteLine(...A) above.

I had thought that by declaring A as a PUBLIC field of the Constants
class that it would be accessable by my Test class.

Can someone please explain the error that I have made.

Indebted for your time,

GM.
Oct 12 '06 #2
gw********@hotmail.com wrote:
Hello, would you please consider the following small piece of code.

using System;

class Constants
{
public const int A = B;
public const int B = 2;
}

class Test
{
static void Main()
{
Console.WriteLine("{0}", A);
}
}

I am getting an error that 'A does not exist in the current context'
for Console.WriteLine(...A) above.

I had thought that by declaring A as a PUBLIC field of the Constants
class that it would be accessable by my Test class.

Can someone please explain the error that I have made.

Indebted for your time,

GM.
Hi GM,

You need to specify which class A is coming from. It's perfectly valid to
have two public constants of the same name, provided they are in different
types. You distinguish between them by qualifying the typename, like this:

///
Console.WriteLine( "{0}", Constants.A );
///

--
Hope this helps,
Tom Spink

Google first, ask later.
Oct 12 '06 #3

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

Similar topics

5
by: David Gray | last post by:
Greetings all, How can I use ADODB to return all tables in an access DB chosen by the user? I'm able so far to select the DB file and build up my connect string, but I would like to offer a...
9
by: hope | last post by:
Hi Access 97 I'm lost on this code please can you help ================================= Below is some simple code that will concatenate a single field's value from multiple records into a...
2
by: Chris Millar | last post by:
Can anyone help me on converting this vb asp page to C#, thanks in advance. chris. <!DOCTYPE HTML PUBLIC "-//W3C//Dtd HTML 4.0 transitional//EN"> <%...
10
by: darrel | last post by:
I'm still trying to sort out in my head the differences between public and shared when referring to declaring properties or variables. This is my understanding: shared - akin to a 'global'...
2
by: I am Sam | last post by:
Ok I set up a button column to delete an individual record. Nothing happens when I test it. Someone please help understand why. Below is the associated coding: DataGrid control: ...
2
by: Sam Samnah | last post by:
I am building a custome control and I need to access the information in the hidden field (HtmlInputHidden HIH) so that when a button is pressed the information in the hidden fields value is...
32
by: robert d via AccessMonster.com | last post by:
I'm looking at converting DAO to ADO in my app. All of my DAO connections are of the following structure: Dim wsName As DAO.Workspace Dim dbName As DAO.Database Dim rsName As DAO.Recordset ...
9
by: pic078 via AccessMonster.com | last post by:
I need serious help - I have a frontend/backend Access database (2 MDE Files) that remains stuck in task manager after exiting the application - you can't reopen database after exiting as a result...
2
by: cephal0n | last post by:
I have this peroblem thats really bugging me for days, please have a patience to read it and help me find the probplem because I knew I missed it and just cant tell where. I have a table named...
20
by: d.s. | last post by:
I've got an app with two classes, and one class (InventoryInfoClass) is an object within the other class (InventoryItem). I'm running into problems with trying to access (get/set) a private...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.