473,378 Members | 1,436 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,378 software developers and data experts.

Constants

OK, my brain has turned to mush on this one.

I want to implement some constant integers that can be used by several
classes in the same namespace. i.e.

namespace MySpace
{
const int THEBOXWIDTH = 24;
const int THEBOXHEIGHT = 48;

class A
{
private int theHeight = THEBOXHEIGHT;
}

class B
{
private int theHeight = THEBOXHEIGHT;
}
}

How can I achieve this? Am I going to have to use enums?

Thanks in advance

Mike

Jan 12 '06 #1
3 1385
Publicjoe wrote:
OK, my brain has turned to mush on this one.

I want to implement some constant integers that can be used by several
classes in the same namespace. i.e.

namespace MySpace
{
const int THEBOXWIDTH = 24;
const int THEBOXHEIGHT = 48;

<snip>

Constants must be placed inside a class.

--
Lasse Vågsæther Karlsen
http://usinglvkblog.blogspot.com/
mailto:la***@vkarlsen.no
PGP KeyID: 0x2A42A1C2
Jan 12 '06 #2
You could just wrap them in another class.

internal class Constants
{
public const int THEBOXWIDTH = 24;
public const int THEBOXHEIGHT = 48;
}

public class A
{
private int theHeight = Constants.THEBOXHEIGHT;
}

public class B
{
private int theHeight = Constants.THEBOXHEIGHT;
}

--
Tim Wilson
..NET Compact Framework MVP

"Publicjoe" <mi**@publicjoe.co.uk> wrote in message
news:us*************@TK2MSFTNGP15.phx.gbl...
OK, my brain has turned to mush on this one.

I want to implement some constant integers that can be used by several
classes in the same namespace. i.e.

namespace MySpace
{
const int THEBOXWIDTH = 24;
const int THEBOXHEIGHT = 48;

class A
{
private int theHeight = THEBOXHEIGHT;
}

class B
{
private int theHeight = THEBOXHEIGHT;
}
}

How can I achieve this? Am I going to have to use enums?

Thanks in advance

Mike

Jan 12 '06 #3
Thanks, works a treat.

Mike

"Tim Wilson" <TIM(UNDERSCORE)WILSON(AT)ROGERS(PERIOD)COM> wrote in message
news:el**************@TK2MSFTNGP10.phx.gbl...
You could just wrap them in another class.

internal class Constants
{
public const int THEBOXWIDTH = 24;
public const int THEBOXHEIGHT = 48;
}

public class A
{
private int theHeight = Constants.THEBOXHEIGHT;
}

public class B
{
private int theHeight = Constants.THEBOXHEIGHT;
}

--
Tim Wilson
.NET Compact Framework MVP

"Publicjoe" <mi**@publicjoe.co.uk> wrote in message
news:us*************@TK2MSFTNGP15.phx.gbl...
OK, my brain has turned to mush on this one.

I want to implement some constant integers that can be used by several
classes in the same namespace. i.e.

namespace MySpace
{
const int THEBOXWIDTH = 24;
const int THEBOXHEIGHT = 48;

class A
{
private int theHeight = THEBOXHEIGHT;
}

class B
{
private int theHeight = THEBOXHEIGHT;
}
}

How can I achieve this? Am I going to have to use enums?

Thanks in advance

Mike


Jan 12 '06 #4

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

Similar topics

8
by: Raymond Hettinger | last post by:
Comments are invited on the following proposed PEP. Raymond Hettinger ------------------------------------------------------- PEP: 329
0
by: David W. Fenton | last post by:
Today I was working on a hideous old app that I created a long time ago that does a lot of showing/hiding/resizing of fields on one of the forms. I had used constants to store reference values for...
13
by: Andrew | last post by:
I use conditional compiler constants, set through the VBA IDE in Tools, <projectname> Properties, that I refer to throughout my code to control which code is used during development, and which...
4
by: Amadelle | last post by:
Hi all and thanks again in advance, What is the best way of defining global constants in a C# application? (A windows application with no windows forms - basically a set of classes). Would it be...
8
by: Marty | last post by:
Hi, I'm new to C#, I used to code in VB.NET. Where is the best place to declare all my constants and global objects in my C# project to have them accessible globally? I have an event logger...
34
by: newsposter0123 | last post by:
The code block below initialized a r/w variable (usually .bss) to the value of pi. One, of many, problem is any linked compilation unit may change the global variable. Adjusting // rodata const...
6
by: PC | last post by:
Gentlesofts, Forgive me. I'm an abject newbie in your world, using VB 2005 with the dot-Net wonderfulness. So, I'm writing a wonderful class or two to interface with a solemnly ancient...
17
by: Neil Cerutti | last post by:
The Glk API (which I'm implementing in native Python code) defines 120 or so constants that users must use. The constants already have fairly long names, e.g., gestalt_Version, evtype_Timer,...
2
by: Leslie Sanford | last post by:
I want to define a set of floating point constants using templates insteand of macros. I'd like to determine whether these constants are floats or doubles at compile time. In my header file, I have...
54
by: shuisheng | last post by:
Dear All, I am always confused in using constants in multiple files. For global constants, I got some clues from http://msdn.microsoft.com/en-us/library/0d45ty2d(VS.80).aspx So in header...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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...

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.