Question

Duplicate

typedef in C#?


Is there a way to create actually keywords in C#. Like for example turning object x into a datatype like int? I guess I'm asking is there anything like a typedef for C# and if not how can I actually make my own types that look like this:

public static crap Main(string[] args)
{
    // Note 'crap' and not 'void'!
}
Was it helpful?

Solution

You can create synonyms for classes such as Int32 or String, but not int or void because those are keywords. The syntax looks like this:

    using foo = System.Int32;

OTHER TIPS

C# intentionally does not provide C/C++ style macros (using #define). You cannot invent these kind of language features and extend the language beyond types. There are good reasons they left this feature out. If you really need these kind of features, you can always run the C# source file through a C preprocessor and compile the resulting file with a C# compiler. You can also rely on other templating features provided by your environment (most likely Visual Studio T4 engine).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top