OK, I have an invoice object.
Within that object I have an InvoiceHead object and list of InvoiceDetail Objects.
Below is my code to create these classes in this order.
The invoice - which has a head, detail List (invoice lines) and then code for a single detail in it (so in the UI can create a single line)
The InvoiceHead object - contains data that is the same for the whole invoice - like invoice number
The InvoiceDetailList object (lines on the invoices) - which is a list of details
The InvoiceDetail object (a single line on the invoice)
Now, I create the invoice, populate the invoice details with no problem. I actually use a for loop to do populate the list.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MyObjects
{
[Serializable]
public class MyApInvoice
{
public Int32 IsSuccessful { get; set; }
public string Message { get; set; }
public Int32 DetailLength { get; set; }
public MyAPInvoiceHead MyApInvHeader = new MyAPInvoiceHead();
public MyAPInvoiceDetail MyApInvDetail = new MyAPInvoiceDetail();
public MyAPInvoiceDetailList MyApInvDetailList = new MyAPInvoiceDetailList();
public MyApInvoice()
{
}
}
[Serializable]
public class MyAPInvoiceHead
{
public string Company { get; set; }
public string InvoiceNum { get; set; }
public DateTime InvoiceDate { get; set; }
}
[Serializable]
public class MyAPInvoiceDetailList
{
public int Length { get; set; }
public List<MyAPInvoiceDetail> invoiceLine = new List<MyAPInvoiceDetail>();
}
[Serializable]
public class MyAPInvoiceDetail
{
public string Company { get; set; }
public string InvNum { get; set; }
public Int32 InvLine { get; set; }
public MyAPInvoiceDetail()
{
}
}
}
Now I want to loop through the list later in my code with a foreach statment. But I get an error saying the list isn't enumerable.
Here's the code I use to try to enumerate the detail list.
But that is where I get the error. My list isn't enumerable. I'm sort of unclear on this because I thought that all lists were enumerable. But I've ran into this before so it would seem I'm wrong. Not all list are enumerable. But I'm pretty sure I can make it enumerable. But how?
// create the detail list object called apInvDtlList and populate the lines in the list with a for loop
...
// now loop/enumerate through this list with a foreach statement
foreach (MyAPInvoiceDetail dtl in apInvDtlList)
{
}
What am I missing? What can I do to make my list enumerable?