19
juin
2007
Un « bug » sur les délégués en VB .NET 2005 corrigé avec VB 9
juin
2007
En C#2.0, imaginons le code suivant :
public class MyCollection : IEnumerable<string>
{
[...]
}
public delegate IEnumerable CreateMyCollectionDelegate();
{
[...]
}
public delegate IEnumerable CreateMyCollectionDelegate();
Il est parfaitement possible d’écrire ceci :
public void Test()
{
CreateMyCollectionDelegate test = new CreateMyCollectionDelegate(CreateMyCollection);
}
public MyCollection CreateMyCollection()
{
return new MyCollection();
}
{
CreateMyCollectionDelegate test = new CreateMyCollectionDelegate(CreateMyCollection);
}
public MyCollection CreateMyCollection()
{
return new MyCollection();
}
En VB .NET 2005 non !
On a le message suivant à la compilation : Method ‘Public Function CreateMyCollection() As WindowsApplication2.MyCollection’ does not have the same signature as delegate ‘Delegate Function CreateMyCollectionDelegate() As System.Collections.IEnumerable’.
Ce message est absurde vu qu’on a surtypé avec MyCollection au lieu de IEnumerable.
En VB9, ce problème a été corrigé.