Is it possible somehow to define a constant that says what datatype to use for certain variables, similar to generics? So in a certain class I would have something like the following:
MYTYPE = System.String;
// some other code here
MYTYPE myVariable = "Hello";
From the principle it should do the same as generics but I don’t want to write the datatype every time the constructor for this class is called. It should simply guarantee that for two (or more) variables the same datatype is used.
Well, you can use a
usingdirective:However, that isn’t really like a typedef – in particular, this code is now perfectly valid:
The compiler knows they’re still the same type.
It’s not really clear what you’re trying to achieve, particularly here:
What do you mean?
Note that using directives are specific to a source file, not to a whole project.