Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Redimensioning an array in c#
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows 10
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01627021
Message ID:
01627183
Vues:
58
Makes sense! I would not even need the invoice class, I can split after I retrieve.... Thank you so much.

Need to get used to the idea of "explicit operator" also. Looks hot! :)

>Depending on what you need you could use a class for invoice. e.g.
public class Invoice
>    {
>        public static explicit operator Invoice(string fields)
>        {
>            string[] array = fields.Split("\t"[0]).ToArray();
>            var inv = new Invoice();
>            inv.InvoiceNumber = Convert.ToInt32(array[0]);
>            inv.InvoiceDate = Convert.ToDateTime(array[1]);
>            inv.Company = array[2];
>            //etc
>            return inv;
>        }
>        public DateTime InvoiceDate { get; set; }
>        public int InvoiceNumber { get; set; }
>        public decimal Amount { get; set; }
>        public string Company { get; set; }
>    }
Your code could then just be:
IEnumerable<Invoice> invoices = File.ReadAllLines(fileName).Select(s => (Invoice)s);
>//Do whatever

If things have the tendency to go your way, do not worry. It won't last. Jules Renard.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform