Using system; using system. collections. generic; using system. LINQ; using system. text; namespace colorfulconsole {public class program {public static void main (string [] ARGs) {// create some dummy data so we have // something to display list <accounts> accts = createaccounts (); // set the foreground and background colors // using the console's foreground and backgroundcolor // properties-here we are setting it up to show // white characters on a dark blue background Console. foregroundcolor = consolecolor. white; console. backgroundcolor = consolecolor. darkblue; // write the banner to screen using writeline console. writeline ("************************************* ****************"); console. writeline ("**"); console. writeline ("* Summary of Accounts (by last name) *"); console. writeline ("**"); console. writeline ("************************************* ****************"); // Add a couple of new lines to break up the banner // from the rest of the text console. write ("\ n"); // use LINQ to objects to order the list by last name var q = (from a in accts orderby. lastname ascending select ). tolist <accounts> (); // display the list in the console foreach (Accounts A in Q) {// set the foreground and background colors // using the console's foreground and backgroundcolor // properties-here we are setting it up to show // white characters on a black background Console. foregroundcolor = consolecolor. white; console. backgroundcolor = consolecolor. black; // write out the name title using console. write console. write ("name:"); // change the foreground color and finish the // line with the name of the account holder // (two colors in one line) console. foregroundcolor = consolecolor. cyan; console. backgroundcolor = consolecolor. black; console. write ("\ t" +. lastname + "," +. firstname + "" +. middlename + "\ n"); // reset to white characters on black // and write out the next line title console. foregroundcolor = consolecolor. white; console. backgroundcolor = consolecolor. black; console. write ("Account type:"); // change colors and finish the Account type line console. foregroundcolor = consolecolor. blue; console. backgroundcolor = consolecolor. black; console. write ("\ t" +. typeofaccount + "\ n"); // check the balance to see if the account // holder is in the red if (. balance <0) {// set the colors to write the title portion // of the line console. foregroundcolor = consolecolor. white; console. backgroundcolor = consolecolor. black; console. write ("balance:"); // The account holder is in debt so show // their negative balance in red console. foregroundcolor = consolecolor. red; console. backgroundcolor = consolecolor. black; console. write ("\ t" +. balance + "\ n");} else {// set the colors to write the title portion // of the line console. foregroundcolor = consolecolor. white; console. backgroundcolor = consolecolor. black; console. write ("balance:"); // The account holder has a positive balance // so show their balance in green console. foregroundcolor = consolecolor. green; console. backgroundcolor = consolecolor. black; console. write ("\ t" +. balance + "\ n") ;}// beep on completion console. write ("\ A"); // wait for the user to read the information console. read ();} /// <summary> // This function creates a group of phony accounts // information so we have something to display /// </Summary> // <returns> </returns> Public static list <accounts> createaccounts () {// create a typed list to contain // account information list <accounts> List = new list <accounts> (); // create and populate an account // and then add it to the list accounts acct1 = new accounts (); acct1.firstname = "William"; acct1.middlename = "Alexander "; acct1.lastname = "Carson"; acct1.typeofaccount = accounts. accounttype. checking; acct1.balance = 121.50 m; List. add (acct1); // create and populate an account // and then add it to the list accounts acct2 = new accounts (); acct2.firstname = "Barney "; acct2.middlename = "Hubert"; acct2.lastname = "forexample"; acct2.typeofaccount = accounts. accounttype. checking; acct2.balance = 1066.33 m; List. add (acct2); // create and populate an account // and then add it to the list accounts acct3 = new accounts (); acct3.firstname = "Julia "; acct3.middlename = "Mildred"; acct3.lastname = "Daniels"; acct3.typeofaccount = accounts. accounttype. savings; acct3.balance = 3397.58 m; List. add (acct3); // create and populate an account // and then add it to the list accounts acct4 = new accounts (); acct4.firstname = "Alvin "; acct4.middlename = "Micheal"; acct4.lastname = "Bixby"; acct4.typeofaccount = accounts. accounttype. checking; acct4.balance =-33.77 m; List. add (acct4); // create and populate an account // and then add it to the list accounts acct5 = new accounts (); acct5.firstname = "Boris "; acct5.middlename = "Winston"; acct5.lastname = "carloff"; acct5.typeofaccount = accounts. accounttype. christmas; acct5.balance = 14551.52 m; List. add (acct5); // create and populate an account // and then add it to the list accounts acct6 = new accounts (); acct6.firstname = "Debra "; acct6.middlename = "Michelle"; acct6.lastname = "silvera"; acct6.typeofaccount = accounts. accounttype. savings; acct6.balance = 936.93 m; List. add (acct6); // create and populate an account // and then add it to the list accounts acct7 = new accounts (); acct7.firstname = "Camden "; acct7.middlename = "Alphonse"; acct7.lastname = "Villalobos"; acct7.typeofaccount = accounts. accounttype. checking; acct7.balance =-71.29 m; List. add (acct7); // create and populate an account // and then add it to the list accounts acct8 = new accounts (); acct8.firstname = "Drake "; acct8.middlename = "Duk"; acct8.lastname = "mallard"; acct8.typeofaccount = accounts. accounttype. christmas; acct8.balance = 815.18 m; List. add (acct8); // create and populate an account // and then add it to the list accounts acct9 = new accounts (); acct9.firstname = "Talbert "; acct9.middlename = "Daz"; acct9.lastname = "yatz"; acct9.typeofaccount = accounts. accounttype. savings; acct9.balance = 14.21 m; List. add (acct9); // create and populate an account // and then add it to the list accounts acct10 = new accounts (); acct10.firstname = "miaxwif "; acct10.middlename = "Isa"; acct10.lastname = "nidmare"; acct10.typeofaccount = accounts. accounttype. checking; acct10.balance =-19697.33 m; List. add (acct10); // return the list of dummy data to the caller return list ;}} /// <summary> // a class used to contain phony account information // </Summary> public class accounts {// set up an enumeration to // define the possible account // types public Enum accounttype {checking, savings, Christmas} // Private member variables private string mfirstname; private string mmiddlename; private string mlastname; private accounttype maccttype; private decimal mbalance; // default constructor Public Accounts () {}// properties Public String firstname {get {return mfirstname;} set {mfirstname = value ;}} Public String middlename {get {return mmiddlename ;} set {mmiddlename = value ;}} Public String lastname {get {return mlastname ;}set {mlastname = value ;}} public accounttype typeofaccount {get {return maccttype ;} set {maccttype = value ;}} public decimal balance {get {return mbalance ;}set {mbalance = value ;}}}}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service