2009-06-05 183 views
1

可能重复:
typedef in C#?
STL like containter typedef shortcut?类型名称混淆

我在想,如果有一个相当于输入函数式语言混淆,我可以在使用C#

例如,在一个像Haskell这样的很好的函数式语言中,我可以像下面这样将一个现有类型别名到一个自定义类型名称

type MyCustomTypeName = String 

我想这样做,因为我有一个API,我正在建立的地方我使用的一些对象有多个可能的名称,他们可以通过几个术语来引用可互换和等同。据推测,我可以用继承来做到这一点,但似乎有点笨重,然后可能会打破,如果人们开始扩大非规范类,即。

public class CanonicalClass { 
    //Full Implementation 
} 

public class AlternateName : CanonicalClass { 
//Empty except I'll need to redefine all the constructors 
//Could declare it sealed but doesn't get rid of the need to redefine constructors 
} 

而且任何人之前提到的问题界面中的所有类都已经全部实现接口,并有这些接口的多个不同实现。

+0

Exact dupe:http://stackoverflow.com/questions/161477/typedef-in-c – 2009-06-05 10:46:38

回答

0

根据你实际想要做什么(给出一个更完整的例子),你可能确实需要接口(正确使用)和/或泛型。