I have this classes:
interface Info{}
class AInfo : Info { }
class BInfo : Info { }
class SendInfo {
static public f_WriteInfo(params Info[] _info) {
}
}
class Test {
static void Main() {
SendInfo.f_WriteInfo(
new[] {
new AInfo(){ ... },
new BInfo(){ ... },
} );
// This will generate an error.
// There will be need casting between new and [] like new Info[]
}
}
Is there any way to do this without casting?
Like:
class SendInfo {
static public f_WriteInfo(params T _info) where T : Info {
Set your method signature to be:
and call it like: