468,514 Members | 1,642 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,514 developers. It's quick & easy.

Constants and thread safety

Hi all,

All of the classes in my DAL are static, with constants defining the
stored procedures and parameters. I've been having some problems with
my site which makes me wonder if there's a thread safety issue.

Are consts thread safe? Would the following example create any thread
safety issues? Would you recommend using static readonly members
instead of constants?

public static class Test
{
private const string TEST_ME = "test";

public static void DoSomething()
{
AnotherStaticClass.DoSomethingElse(TEST_ME);
}
}

Thanks,

Paul

Apr 11 '07 #1
1 3173
Paul,

Constants are thread-safe. You can not modify the value of constants at
runtime, so there are no thread-safety issues.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<pa*********@gmail.comwrote in message
news:11*********************@b75g2000hsg.googlegro ups.com...
Hi all,

All of the classes in my DAL are static, with constants defining the
stored procedures and parameters. I've been having some problems with
my site which makes me wonder if there's a thread safety issue.

Are consts thread safe? Would the following example create any thread
safety issues? Would you recommend using static readonly members
instead of constants?

public static class Test
{
private const string TEST_ME = "test";

public static void DoSomething()
{
AnotherStaticClass.DoSomethingElse(TEST_ME);
}
}

Thanks,

Paul

Apr 11 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Jonathan Burd | last post: by
9 posts views Thread by Alexander Fleck | last post: by
8 posts views Thread by Marty | last post: by
4 posts views Thread by Warren Sirota | last post: by
6 posts views Thread by fniles | last post: by
1 post views Thread by paul.hester | last post: by
13 posts views Thread by arun.darra | last post: by
reply views Thread by Graham Wideman | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.