Guest User

Untitled

a guest
Dec 11th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. using System;
  2.  
  3. [assembly: Trace.QuickTrace(AttributeTargetAssemblies = "PostSharpIntro", AttributeTargetTypes = "PostSharpIntro.*")]
  4.  
  5. namespace PostSharpIntro
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. System.Diagnostics.Trace.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(Console.Out));
  12.  
  13. try
  14. {
  15. var calculator = new Calculator();
  16. int a = 7, b = 5, result;
  17.  
  18. string message = "Welcome to the PostSharpIntro project";
  19. Console.WriteLine(message);
  20.  
  21. result = calculator.Add(a, b);
  22. message = string.Format("{0} add {1} equals {2}", a, b, result);
  23. Console.WriteLine(message);
  24.  
  25. result = calculator.Subtract(a, b);
  26. message = string.Format("{0} subtract {1} equals {2}", a, b, result);
  27. Console.WriteLine(message);
  28.  
  29. calculator.RunUnstableCode();
  30. }
  31. catch (Exception e)
  32. {
  33. Console.WriteLine(e.Message);
  34. }
  35. finally
  36. {
  37. Console.WriteLine("Press any yet to exit...");
  38. Console.ReadKey();
  39. }
  40. }
  41.  
  42. public class Calculator
  43. {
  44. internal int Add(int a, int b)
  45. {
  46. return a + b;
  47. }
  48.  
  49. internal int Subtract(int a, int b)
  50. {
  51. return a - b;
  52. }
  53.  
  54. internal void RunUnstableCode()
  55. {
  56. throw new Exception("Houston, we have a problem!");
  57. }
  58. }
  59. }
  60. }
Add Comment
Please, Sign In to add comment