C# Printing a List -
so, im working on code class involving lists.
i have this
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; namespace excercise_1 { class program { static void main(string[] args) { card c1 = new card("1112211", "jhon", "brown", "wollongong", 2500, 1500); card c2 = new card("1111457", "sibel", "yilmaz", "figtree", 3251, 3000); card c3 = new card("3333333", "suzan", "yilmaz", "gywnville", 3000, 5000); card c4 = new card("4444444", "bob", "brown", "balgownie", 1457, 2000); c1.print(); c2.print(); list<card> cards = new list<card>(); cards.add(c3); cards.add(c4); } } class card { public string id; public string first_name; public string family_name; public string suburb; public int postcode; public int balance; public card (string id, string first_name, string family_name, string suburb, int postcode, int balance) { this.id = id; this.first_name = first_name; this.family_name = family_name; this.suburb = suburb; this.postcode = postcode; this.balance = balance; } public void print() { console.writeline(this.id); console.writeline(this.first_name); console.writeline(this.family_name); console.writeline(this.suburb); console.writeline(this.postcode); console.writeline(this.balance); } } }
i need able print list called cards. have tried variety of methods, nothing working , i'm getting more , more frustrated. if able appreciated.
why don't use simple loop ?
foreach(var card in cards) card.print();
btw, might consider overriding tostring
class instead of print
method.
Comments
Post a Comment