2009-06-05 184 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

根據你實際想要做什麼(給出一個更完整的例子),你可能確實需要接口(正確使用)和/或泛型。