471,350 Members | 1,934 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 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 1337
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Amadelle | last post: by
8 posts views Thread by Marty | last post: by
34 posts views Thread by newsposter0123 | last post: by
17 posts views Thread by Neil Cerutti | last post: by
2 posts views Thread by Leslie Sanford | last post: by
54 posts views Thread by shuisheng | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.