Structs with constants

G

gutofb7

Hi folks!

I have a class A, with an inner class B. This inner class B contains
only string constants. So, I will never have an instance of B. My
silly question is: would I have any benefit of changing B to a struct?
Since constants will be replaced at compile time, what would hapen
with this class/struct? This leads me to another question: if I have a
static class that provides only methods, could be any benefit of
changing it to a struct?
A work colleague came up with these questions, and I have no idea of
what to say (although I tend to think that I wouldn't have any
benfits).

What do you think??

thanks
 
G

gutofb7

Note that since a struct can't be static, a class is a much better choice 
for a type that is specifically intended to have no instance members,  
simply because the code can be written in a more self-documenting way.  
But that's a code maintenance issue.  There should be no practical  
performance difference between the two and IMHO definitely no _advantage_ 
to using a struct instead of a class.

Pete

Thanks! that's what I thought!
 

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