Constants and thread safety

P

paul.hester

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
 
C

Chris Mullins [MVP]

Hi Paul,

Constants are thread safe - I've been using them that way forever.

The example you're showing here doesn't have any thread issues associated
with it that I can see.

(Tell Greg & everyone, that I said hello...)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top