Type equivalence/identity

  • Thread starter Thread starter ozbear
  • Start date Start date
O

ozbear

In C# is there a way to alias or equivalence one type to another?

For example, in Delphi, I can say...

type TMyFloat = type double;

and then cheerfully use TMyFloat in my field definitions, return
value declarations for functions, declaring variables and formal
procedure/function/method arguments. If at a later time -double-
turns out to be a suboptimal choice I can change the lone type
declaration to say....

type TMyFloat = type Extended;

and recompile without having to change all of the declarations
elsewhere in my application.

I could subclass non-sealed classes to achieve something like this
but for C#'s sealed supplied classes, like changing my mind to
use Decimal instead of double, I can't think of a way.

Any ideas?

Oz
 
You can use 'using' to alias namespaces in addition to Types:

namespace MyNamespace.Using
{
class A {}
}
namespace SomeNamespace
{
using MyAlias = MyNamespace.Using;
class B: MyAlias.A {}
}

Martha
 
Ignore this guy he is spoofing my email account. For credibility purposes I
suppose.
 
Back
Top