C # keyword override?

Is it possible to override a C # keyword, such as int , to use Int64 instead of Int32?

If not, how can this be done? I want the flexibility to override the int I use, so later I could change it to int64 if I wanted, instead of going around all the int values โ€‹โ€‹manually.

+4
source share
4 answers

No, this is not possible, and you really should not do it. Overriding keywords for custom values โ€‹โ€‹will only make your code less readable and maintainable. People familiar with your code base will have to forget everything they know about C # defaults and find out their defaults. This is not a good way to create a supported code base.

What you should consider is creating a new type name and using "use an alias" to redirect that type inside your code base.

 using FexibleInt = System.Int32; 
+18
source

Add

 using MyIntType = System.Int64; 

after the namespace declaration.

+4
source

Sorry - this cannot be done with C # unless you put all your files through a preprocessor before compiling them.

+1
source

I do not think so. Are you trying to use the same functionality as typedef in C ++?

One thing you can do is encapsulate an int in a user defined class / struct.

or

using MyIntType = System.Int64;

+1
source

All Articles