static void Main() { // Get the data from some data source. var employees = InitializeData(); // Display application title. string title = UILibrary.GetTitle(); int start = (Console.WindowWidth + title.Length) / 2; string titlefmt = String.Format("{{0,{0}{1}", start, "}"); Console.WriteLine(titlefmt, title); Console.WriteLine(); // Retrieve resources. string[] fields = UILibrary.GetFieldNames(); int[] lengths = UILibrary.GetFieldLengths(); string fmtString = String.Empty; // Create format string for field headers and data. for (int ctr = 0; ctr < fields.Length; ctr++) { fmtString += String.Format("{{{0},-{1}{2}{3} ", ctr, lengths[ctr], ctr >= 2 ? ":d" : "", "}"); } // Display the headers. Console.WriteLine(fmtString, fields); Console.WriteLine(); // Display the data. foreach (var e in employees) { Console.WriteLine(fmtString, e.Item1, e.Item2, e.Item3, e.Item4); } Console.ReadLine(); }
static public void DisplayData(Windows.UI.Xaml.Controls.TextBlock outputBlock) { // Get the data from some data source. var employees = InitializeData(); outputBlock.FontFamily = new FontFamily("Courier New"); // Display application title. string title = UILibrary.GetTitle(); outputBlock.Text += title + Environment.NewLine + Environment.NewLine; // Retrieve resources. string[] fields = UILibrary.GetFieldNames(); int[] lengths = UILibrary.GetFieldLengths(); string fmtString = String.Empty; // Create format string for field headers and data. for (int ctr = 0; ctr < fields.Length; ctr++) { fmtString += String.Format("{{{0},-{1}{2}{3} ", ctr, lengths[ctr], ctr >= 2 ? ":d" : "", "}"); } // Display the headers. outputBlock.Text += String.Format(fmtString, fields) + Environment.NewLine + Environment.NewLine; // Display the data. foreach (var e in employees) { outputBlock.Text += String.Format(fmtString, e.Item1, e.Item2, e.Item3, e.Item4) + Environment.NewLine; } }