|
Exemple 13-25 extrait du chapitre
La généricité
Exemple 13-24< > Exemple 13-26
Cet exemple peut être compilé avec la ligne de commande: csc.exe /target:library Exemple_13_25.cs Erreurs: 1 Avertissements: 0 Remarque:
Exemple_13_25.cs
using System.Collections.Generic;
class C<T> {
public void Fct(T t){
int i = t as int; // Erreur de compilation:
// The as operator must be used with a reference type.
string s = t as string;
if( s!= null ) { /*...*/ }
if( t is IEnumerable<int> ){
IEnumerable<int> enumerable = t as IEnumerable<int>;
foreach( int j in enumerable) { /*...*/ }
}
}
}
Copyright Patrick Smacchia 2006 2007
|