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\n"); // use Linq to Objects to order the list by last name var q = (from a in accts orderby a.LastName ascending select a).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\t\t" + a.LastName + ", " + a.FirstName + " " + a.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\t" + a.TypeOfAccount + "\n"); // check the balance to see if the account // holder is in the red if (a.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\t" + a.Balance + "\n\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\t" + a.Balance + "\n\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 account /// 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.50M; 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 = "Fortner"; acct2.TypeOfAccount = Accounts.AccountType.Checking; acct2.Balance = 1066.33M; 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.58M; 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.77M; 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.52M; 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.93M; 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.29M; 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.18M; 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.21M; 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.33M; 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; } } }}