4
所以,情況是我有一個C#泛型類名爲Foo
與模板參數T
其中有new()
約束。我宣佈我的課是這樣的:C#泛型與IronPython類型參數
class Baz
{
public Baz() { }
}
class Foo<T>
where T : Baz, new()
{
// blah blah
}
而且在Python:
class Bar(Baz):
def __init__(self):
""" do various things here """
然而,如果在Python中,我嘗試做Foo[Bar]
,我得到一個錯誤,告訴我,我的Bar
類違反約束條件(即new()
約束條件)Foo<T>
。
什麼給?
嗯,是的,當我意識到模板實際上放棄了我所有的Python類型信息時,我就是這麼想的。感謝您的確認。 – rfw 2010-09-26 22:19:56
有人可以詳細說明或舉例說明嗎?我對python內部工作的認識並不能幫助我跳到代碼中應該看到的東西。 – Gauthier 2013-07-23 13:25:30
我只是試了幾件事,發現C#函數 somefunc(字符串x){dostuff(); } 必須調用爲 somefunc [sometype](「some string」) –
Gauthier
2013-07-23 13:38:21