typedefing built-in value types?

  • Thread starter Thread starter Matt Wisner
  • Start date Start date
M

Matt Wisner

Hi,

Can anyone tell me what the C# equivalent is to the following C code?

typedef unsigned char mybyte;
typedef unsigned short myword;

I don't want to create 'mybyte' and 'myword' as classes or structs.
Is this possible?

Thx,
Matt
 
How about

Type newInt = typeof(int);

at class level,
or

using newInt = System.Int32;

at a top of every file you need to include that type in?

It's not exactly a typedef, but thats the closest thing

Cheers,
Branimir
 
Matt Wisner said:
Can anyone tell me what the C# equivalent is to the following C code?

typedef unsigned char mybyte;
typedef unsigned short myword;

I don't want to create 'mybyte' and 'myword' as classes or structs.
Is this possible?

The best thing is not to do that, in my view. It lowers readability.
However, you can use using statements:

using mybyte = System.Char;

(Note, however, that a System.Char is *not* a byte. Characters in .NET
are 16 bit unicode plane 0 values.)
 

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

Back
Top