Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Trying To Understand Indexers
Message
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Trying To Understand Indexers
Divers
Thread ID:
01433919
Message ID:
01433919
Vues:
121
I have this customer class:
public class Customer
{
    private List<Invoice> _Invoices = new List<Invoice>();
    public Invoice this[int item]
    {
        get
        {
            return _Invoices[item];
        }
        set
        {
            _Invoices[item] = value;
        }
    }
}
I then do this:
static void Main(string[] args)
{
    Invoice InvA = new Invoice();
    InvA.InvoiceId = "A0001";

    Invoice InvB = new Invoice();
    InvB.InvoiceId = "B0002";

    Customer cust = new Customer();
    cust[0] = InvA;
    cust[1] = InvB;
}
I'm not really seeing a usage for indexers. It seems to me that an Invoices collection would be better. What's the point of indexers?
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform