![](/img/trans.png)
[英]Distinguish between a class generic type parameter and method generic type parameter
[英]determine method parameter type from generic typed class
我有以下情況:
public class CustomDataGridView<T> : DataGridView
{
method1();
...
}
class ChannelsDataGridView : CustomDataGridView<Channel>
{
...
}
class NetworksDataGridView : CustomDataGridView<Network>
{
...
}
我需要方法:
public void Method(TYPE sender)
{
sender.method1();
}
此方法中的TYPE應該是什么?如何實現此功能?
看來您需要通用方法:
public void Method<T>( CustomDataGridView<T> sender )
請注意,如果這是在已經使用T
作為通用參數的通用類中,則應該使用其他字母:
public void Method<U>( CustomDataGridView<U> sender )
您還應該將Method
定義為泛型:
public void Method<T>(CustomDataGridView<T> sender)
{
sender.method1();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.