Hello,
I'm just starting out with c# so the question may appear little trivial. But I couldn't find an answer (I wished to look for)
as in c I can create a small macro to e.g. print the name and value of a constant
#define print_it(x) printf("Name: %s, Value: %d", ##x, x)
and if I have a symbol like
#define CUBE_ARM_WIDTH 5
I'd do it like
print_it(CUBE_ARM_WIDTH);
and I'd get the output as
Name: CUBE_ARM_WIDTH, Value: 5
But how do I do it in c#, where #define is allowed but to give it a value or a function like body is not allowed.
and also suppose I am using a constant value in two different cs files, something like
#define GRID_ARRAY_WIDTH 20
I'll put it in a header file, include it in both files and use the name I #defined freely. But the same can not be done in c# with the same ease.
I know we can use enums. but in that case:
class myShapes
{
enum GridParams
{
GridArrayWidth 20,
GridArrayHeight 20
};
}
my the name that was already a little long, becomes even longer i.e.
myShapes.GridParams.GridArrayWidth
with #define it was 16 characters long and now it is 34 characters.
I think there should be a better way of doing it, which apparently, I have not come across.
So how do I do these things in C#.
Please don't get me wrong, I admire C# a lot for a simple fact that what I could do in VC++ with some files-full of code can be done in few lines in c# which are simple and very intuitive.
I just want to know if I can use some of the things I learned while using C.
Regards,
gdshukla