Generic Lists

January 18, 2007 · Posted by Jeremy Thake
0 Comments · Trackback Url

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.

 

Tags:diigo it



0 responses so far


     

Name:
URL:
Email:
Comments: