Generic Lists

January 18, 2007

I'm sure this is an obvious one, but this is a nice use of the new List with Generics:

            List<DirectDebitsRequestPayment> payments = new List<DirectDebitsRequestPayment>();

            DirectDebitsRequestPayment payment = new DirectDebitsRequestPayment();
            payment.Amount = new decimal();
            payment.FromAccountName = string.Empty; 


            payments.Add(payment);

            request.Payment = payments.ToArray();

instead of sticking with Arrays using:

 
            DirectDebitsRequestPayment[] payments = new DirectDebitsRequestPayment[1];

            DirectDebitsRequestPayment payment = new DirectDebitsRequestPayment();
            payment.Amount = new decimal();
            payment.FromAccountName = string.Empty;
            payments[0] = payment;

            request.Payment = payments;

etc. when you want to add more than one.

 

diigo itdeliciousdiggfacebookreddit

Comments

blog comments powered by Disqus