Skip to content

Instantly share code, notes, and snippets.

@csim
Last active July 30, 2024 19:43

Revisions

  1. csim revised this gist Jul 30, 2024. 1 changed file with 9 additions and 3 deletions.
    12 changes: 9 additions & 3 deletions CS6.cs
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,3 @@
    // What is the output of the short program below? Explain your answer.

    using System;

    public class Program
    @@ -15,21 +13,29 @@ public static void Main()
    Console.WriteLine(ex.Message);
    }

    Console.WriteLine(DoSomething());
    }

    public static int DoSomething() {
    try
    {
    throw new ApplicationException("Exception 2");
    }
    catch (ApplicationException)
    {
    Console.WriteLine("ApplicationException 2");

    return 1;
    }
    catch (Exception ex)
    {
    Console.WriteLine(ex.Message);

    return 2;
    }
    finally
    {
    Console.WriteLine("Finally");
    }
    }
    }
    }
  2. Clint Simon revised this gist Aug 31, 2020. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions CS9.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    Write a function in any language (preferable C#) which computes the angle between hand hands of a clock given a time of day. The function must work for all combinations of hour and minute.
    Write a function in any language (preferable C#) which computes the angle between the hand hands of a clock given a time of day. The function must work for all combinations of hour and minute.

    inputs: int hour, int minute<br/>
    output: float angle (in degrees)
    @@ -15,9 +15,9 @@ At 3:00 PM, the angle is 90 degrees

    At 3:45 PM, the angle is 180 degrees


    ---------.-----




  3. Clint Simon revised this gist Aug 27, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion CS3.cs
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ public class Program
    public static void Main()
    {
    var printers = new List<Action>();
    int i = 0;
    var i = 0;

    for (i = 0; i < 10; i++)
    {
  4. Clint Simon revised this gist Aug 27, 2020. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion CS3.cs
    Original file line number Diff line number Diff line change
    @@ -8,8 +8,9 @@ public class Program
    public static void Main()
    {
    var printers = new List<Action>();
    int i = 0;

    for (int i = 0; i < 10; i++)
    for (i = 0; i < 10; i++)
    {
    printers.Add(() => Console.WriteLine(i));
    }
  5. Clint Simon revised this gist Aug 27, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion CS6.cs
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@ public static void Main()
    {
    throw new ApplicationException("Exception 2");
    }
    catch (ApplicationException ex)
    catch (ApplicationException)
    {
    Console.WriteLine("ApplicationException 2");
    }
  6. Clint Simon revised this gist Aug 27, 2020. No changes.
  7. Clint Simon revised this gist Aug 27, 2020. 8 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
  8. Clint Simon revised this gist Aug 26, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Q9.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    Write a function in any language (preferable C#) which computes the angle between hand hands of a clock given a time of day. The function must work for all combinations of hour and minute.

    inputs: hour and minute
    output: angle (in degrees)
    inputs: int hour, int minute<br/>
    output: float angle (in degrees)

    For Example:

  9. Clint Simon revised this gist Aug 24, 2020. 1 changed file with 0 additions and 26 deletions.
    26 changes: 0 additions & 26 deletions Q8.cs
    Original file line number Diff line number Diff line change
    @@ -1,26 +0,0 @@
    using System;

    public class Program
    {
    public static void Main()
    {
    var circle1 = new Circle {
    Radius = 1
    };

    // Given an instance of the Circle class
    // Write code to calculate the circumference of the circle (2 * pi * r)
    // without modifying the Circle class itself.

    }
    }

    public sealed class Circle
    {
    public double Radius { get; set; }

    public double Calculate(Func<double, double> operation)
    {
    return operation(Radius);
    }
    }
  10. Clint Simon revised this gist Aug 24, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Q9.md
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ At 3:00 PM, the angle is 90 degrees
    .-----


    At 9:45 PM, the angle is 180 degrees
    At 3:45 PM, the angle is 180 degrees


    ---------.-----
  11. Clint Simon revised this gist Aug 24, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Q9.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    Write a function in any language (preferable C#) which computes the angle between hand hands of a clock given a time of day.
    Write a function in any language (preferable C#) which computes the angle between hand hands of a clock given a time of day. The function must work for all combinations of hour and minute.

    inputs: hour and minute
    output: angle (in degrees)
  12. Clint Simon revised this gist Aug 24, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Q9.md
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,7 @@ At 3:00 PM, the angle is 90 degrees
    At 9:45 PM, the angle is 180 degrees


    ---------.-----
    ---------.-----



  13. Clint Simon revised this gist Aug 24, 2020. 2 changed files with 23 additions and 10 deletions.
    23 changes: 23 additions & 0 deletions Q9.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    Write a function in any language (preferable C#) which computes the angle between hand hands of a clock given a time of day.

    inputs: hour and minute
    output: angle (in degrees)

    For Example:

    At 3:00 PM, the angle is 90 degrees

    |
    |
    |
    .-----


    At 9:45 PM, the angle is 180 degrees


    ---------.-----




    10 changes: 0 additions & 10 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -1,10 +0,0 @@
    Write a function in any language (preferable C#) which computes the angle between hand hands of a clock given a time of day.

    inputs: hour and minute
    output: angle (in degrees)

    For Example:

    At 3:00 PM,

    ![](https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.iconfinder.com%2Ficons%2F3903655%2F3am_3pm_clock_icon&psig=AOvVaw16EDfASipAOrSL34JhJELl&ust=1598377259120000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCIjH-baxtOsCFQAAAAAdAAAAABAD)
  14. Clint Simon revised this gist Aug 24, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -7,4 +7,4 @@ For Example:

    At 3:00 PM,

    ![][https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.iconfinder.com%2Ficons%2F3903655%2F3am_3pm_clock_icon&psig=AOvVaw16EDfASipAOrSL34JhJELl&ust=1598377259120000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCIjH-baxtOsCFQAAAAAdAAAAABAD]
    ![](https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.iconfinder.com%2Ficons%2F3903655%2F3am_3pm_clock_icon&psig=AOvVaw16EDfASipAOrSL34JhJELl&ust=1598377259120000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCIjH-baxtOsCFQAAAAAdAAAAABAD)
  15. Clint Simon renamed this gist Aug 24, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  16. Clint Simon revised this gist Aug 24, 2020. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    Write a function in any language (preferable C#) which computes the angle between hand hands of a clock given a time of day.

    inputs: hour and minute
    output: angle (in degrees)

    For Example:

    At 3:00 PM,

    ![][https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.iconfinder.com%2Ficons%2F3903655%2F3am_3pm_clock_icon&psig=AOvVaw16EDfASipAOrSL34JhJELl&ust=1598377259120000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCIjH-baxtOsCFQAAAAAdAAAAABAD]
  17. Clint Simon revised this gist Aug 24, 2020. 6 changed files with 109 additions and 83 deletions.
    10 changes: 10 additions & 0 deletions Q2.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    using System.Linq;
    public class Program
    {
    public static void Main()
    {
    int[] numbers = { 30, 325, 18, 92, 100, 42, 72 };

    // Use linq to find which numbers are evenly divisible by 5.
    }
    }
    20 changes: 16 additions & 4 deletions Q3.cs
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,22 @@
    using System.Linq;
    // What is the output of the program below? Explain your answer.

    using System;
    using System.Collections.Generic;

    public class Program
    {
    public static void Main()
    {
    int[] numbers = { 30, 325, 18, 92, 100, 42, 72 };
    var printers = new List<Action>();

    for (int i = 0; i < 10; i++)
    {
    printers.Add(() => Console.WriteLine(i));
    }

    // Use linq to find which numbers are evenly divisible by 5.
    }
    foreach (var printer in printers)
    {
    printer();
    }
    }
    }
    24 changes: 13 additions & 11 deletions Q4.cs
    Original file line number Diff line number Diff line change
    @@ -1,22 +1,24 @@
    // What is the output of the program below? Explain your answer.

    using System;
    using System.Collections.Generic;
    using System.Threading.Tasks;

    public class Program
    {
    private static string _result = "Nothing";

    public static void Main()
    {
    var printers = new List<Action>();

    for (int i = 0; i < 10; i++)
    {
    printers.Add(() => Console.WriteLine(i));
    }
    SaySomethingAsync();
    Console.WriteLine(_result);
    }

    foreach (var printer in printers)
    {
    printer();
    }
    public static async Task<string> SaySomethingAsync()
    {
    await Task.Delay(5);
    _result = "Something";
    return "SaySomething exited";
    }
    }

    // Also, would the answer change if we were to replace await Task.Delay(5); with Thread.Sleep(5)? Why or why not?
    43 changes: 26 additions & 17 deletions Q5.cs
    Original file line number Diff line number Diff line change
    @@ -1,24 +1,33 @@
    // What is the output of the program below? Explain your answer.
    // What is the output of the short program below? Explain your answer.

    using System;
    using System.Threading.Tasks;

    public class Person
    {
    public string Name { get; set; }
    }

    public class Program
    {
    private static string _result = "Nothing";

    public static void Main()
    {
    SaySomethingAsync();
    Console.WriteLine(_result);
    }
    public static void Main(string[] args)
    {
    var joe = new Person();
    joe.Name = "Joe";

    public static async Task<string> SaySomethingAsync()
    {
    await Task.Delay(5);
    _result = "Something";
    return "SaySomething exited";
    }
    }
    var tim = joe;
    tim.Name = "tim";

    // Also, would the answer change if we were to replace await Task.Delay(5); with Thread.Sleep(5)? Why or why not?
    Console.WriteLine(joe.Name);
    Console.WriteLine(tim.Name);

    var myNumber = 666;
    DoSomething(myNumber);

    Console.WriteLine(myNumber);
    }

    private static void DoSomething(int someNumber)
    {
    someNumber = 777;
    }
    }
    52 changes: 27 additions & 25 deletions Q6.cs
    Original file line number Diff line number Diff line change
    @@ -2,32 +2,34 @@

    using System;

    public class Person
    {
    public string Name { get; set; }
    }

    public class Program
    {
    public static void Main(string[] args)
    {
    var joe = new Person();
    joe.Name = "Joe";

    var tim = joe;
    tim.Name = "tim";

    Console.WriteLine(joe.Name);
    Console.WriteLine(tim.Name);

    var myNumber = 666;
    DoSomething(myNumber);

    Console.WriteLine(myNumber);
    }
    public static void Main()
    {
    try
    {
    throw new Exception("Exception 1");
    }
    catch (Exception ex)
    {
    Console.WriteLine(ex.Message);
    }

    private static void DoSomething(int someNumber)
    {
    someNumber = 777;
    }
    try
    {
    throw new ApplicationException("Exception 2");
    }
    catch (ApplicationException ex)
    {
    Console.WriteLine("ApplicationException 2");
    }
    catch (Exception ex)
    {
    Console.WriteLine(ex.Message);
    }
    finally
    {
    Console.WriteLine("Finally");
    }
    }
    }
    43 changes: 17 additions & 26 deletions Q7.cs
    Original file line number Diff line number Diff line change
    @@ -1,35 +1,26 @@
    // What is the output of the short program below? Explain your answer.

    using System;

    public class Program
    {
    public static void Main()
    {
    try
    {
    throw new Exception("Exception 1");
    }
    catch (Exception ex)
    {
    Console.WriteLine(ex.Message);
    }
    var circle1 = new Circle {
    Radius = 1
    };

    // Given an instance of the Circle class
    // Write code to calculate the circumference of the circle (2 * pi * r)
    // without modifying the Circle class itself.

    }
    }

    try
    {
    throw new ApplicationException("Exception 2");
    }
    catch (ApplicationException ex)
    {
    Console.WriteLine("ApplicationException 2");
    }
    catch (Exception ex)
    {
    Console.WriteLine(ex.Message);
    }
    finally
    {
    Console.WriteLine("Finally");
    }
    public sealed class Circle
    {
    public double Radius { get; set; }

    public double Calculate(Func<double, double> operation)
    {
    return operation(Radius);
    }
    }
  18. Clint Simon revised this gist Aug 20, 2020. 2 changed files with 4 additions and 5 deletions.
    2 changes: 1 addition & 1 deletion Q1.cs
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ public class Program
    public static void Main()
    {
    Console.WriteLine(location == null ? "location is null" : location);
    Console.WriteLine(time == DateTime.MinValue ? "time is null" : time.ToString());
    Console.WriteLine(time == DateTime.MinValue ? "time is MinValue" : time.ToString());
    }
    }

    7 changes: 3 additions & 4 deletions Q3.cs
    Original file line number Diff line number Diff line change
    @@ -3,9 +3,8 @@ public class Program
    {
    public static void Main()
    {
    int[] numbers = { 30, 325, 18, 92, 100, 42, 72 };

    // Use linq to find which numbers are evenly divisible by 5.

    int[] numbers = { 30, 325, 18, 92, 100, 42, 72 };

    // Use linq to find which numbers are evenly divisible by 5.
    }
    }
  19. Clint Simon revised this gist Aug 20, 2020. 6 changed files with 105 additions and 105 deletions.
    27 changes: 6 additions & 21 deletions Q3.cs
    Original file line number Diff line number Diff line change
    @@ -1,26 +1,11 @@
    using System;

    using System.Linq;
    public class Program
    {
    public static void Main()
    {
    var circle1 = new Circle {
    Radius = 1
    };

    // Given an instance of the Circle class
    // Write code to calculate the circumference of the circle (2 * pi * r)
    // without modifying the Circle class itself.

    }
    int[] numbers = { 30, 325, 18, 92, 100, 42, 72 };

    // Use linq to find which numbers are evenly divisible by 5.

    }
    }

    public sealed class Circle
    {
    public double Radius { get; set; }

    public double Calculate(Func<double, double> operation)
    {
    return operation(Radius);
    }
    }
    24 changes: 11 additions & 13 deletions Q4.cs
    Original file line number Diff line number Diff line change
    @@ -1,24 +1,22 @@
    // What is the output of the program below? Explain your answer.

    using System;
    using System.Threading.Tasks;
    using System.Collections.Generic;

    public class Program
    {
    private static string _result = "Nothing";

    public static void Main()
    {
    SaySomethingAsync();
    Console.WriteLine(_result);
    }
    var printers = new List<Action>();

    for (int i = 0; i < 10; i++)
    {
    printers.Add(() => Console.WriteLine(i));
    }

    public static async Task<string> SaySomethingAsync()
    {
    await Task.Delay(5);
    _result = "Something";
    return "SaySomething exited";
    foreach (var printer in printers)
    {
    printer();
    }
    }
    }

    // Also, would the answer change if we were to replace await Task.Delay(5); with Thread.Sleep(5)? Why or why not?
    24 changes: 13 additions & 11 deletions Q5.cs
    Original file line number Diff line number Diff line change
    @@ -1,22 +1,24 @@
    // What is the output of the program below? Explain your answer.

    using System;
    using System.Collections.Generic;
    using System.Threading.Tasks;

    public class Program
    {
    private static string _result = "Nothing";

    public static void Main()
    {
    var printers = new List<Action>();

    for (int i = 0; i < 10; i++)
    {
    printers.Add(() => Console.WriteLine(i));
    }
    SaySomethingAsync();
    Console.WriteLine(_result);
    }

    foreach (var printer in printers)
    {
    printer();
    }
    public static async Task<string> SaySomethingAsync()
    {
    await Task.Delay(5);
    _result = "Something";
    return "SaySomething exited";
    }
    }

    // Also, would the answer change if we were to replace await Task.Delay(5); with Thread.Sleep(5)? Why or why not?
    40 changes: 31 additions & 9 deletions Q6.cs
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,33 @@
    using System.Linq;
    // What is the output of the short program below? Explain your answer.

    using System;

    public class Person
    {
    public string Name { get; set; }
    }

    public class Program
    {
    public static void Main()
    {
    int[] numbers = { 30, 325, 18, 92, 100, 42, 72 };

    // Use linq to find which numbers are evenly divisible by 5.

    }
    }
    public static void Main(string[] args)
    {
    var joe = new Person();
    joe.Name = "Joe";

    var tim = joe;
    tim.Name = "tim";

    Console.WriteLine(joe.Name);
    Console.WriteLine(tim.Name);

    var myNumber = 666;
    DoSomething(myNumber);

    Console.WriteLine(myNumber);
    }

    private static void DoSomething(int someNumber)
    {
    someNumber = 777;
    }
    }
    52 changes: 27 additions & 25 deletions Q7.cs
    Original file line number Diff line number Diff line change
    @@ -2,32 +2,34 @@

    using System;

    public class Person
    {
    public string Name { get; set; }
    }

    public class Program
    {
    public static void Main(string[] args)
    {
    var joe = new Person();
    joe.Name = "Joe";

    var tim = joe;
    tim.Name = "tim";

    Console.WriteLine(joe.Name);
    Console.WriteLine(tim.Name);

    var myNumber = 666;
    DoSomething(myNumber);

    Console.WriteLine(myNumber);
    }
    public static void Main()
    {
    try
    {
    throw new Exception("Exception 1");
    }
    catch (Exception ex)
    {
    Console.WriteLine(ex.Message);
    }

    private static void DoSomething(int someNumber)
    {
    someNumber = 777;
    }
    try
    {
    throw new ApplicationException("Exception 2");
    }
    catch (ApplicationException ex)
    {
    Console.WriteLine("ApplicationException 2");
    }
    catch (Exception ex)
    {
    Console.WriteLine(ex.Message);
    }
    finally
    {
    Console.WriteLine("Finally");
    }
    }
    }
    43 changes: 17 additions & 26 deletions Q8.cs
    Original file line number Diff line number Diff line change
    @@ -1,35 +1,26 @@
    // What is the output of the short program below? Explain your answer.

    using System;

    public class Program
    {
    public static void Main()
    {
    try
    {
    throw new Exception("Exception 1");
    }
    catch (Exception ex)
    {
    Console.WriteLine(ex.Message);
    }
    var circle1 = new Circle {
    Radius = 1
    };

    // Given an instance of the Circle class
    // Write code to calculate the circumference of the circle (2 * pi * r)
    // without modifying the Circle class itself.

    }
    }

    try
    {
    throw new ApplicationException("Exception 2");
    }
    catch (ApplicationException ex)
    {
    Console.WriteLine("ApplicationException 2");
    }
    catch (Exception ex)
    {
    Console.WriteLine(ex.Message);
    }
    finally
    {
    Console.WriteLine("Finally");
    }
    public sealed class Circle
    {
    public double Radius { get; set; }

    public double Calculate(Func<double, double> operation)
    {
    return operation(Radius);
    }
    }
  20. Clint Simon revised this gist Aug 19, 2020. No changes.
  21. Clint Simon revised this gist Aug 19, 2020. No changes.
  22. Clint Simon revised this gist Aug 19, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Q3.cs
    Original file line number Diff line number Diff line change
    @@ -19,8 +19,8 @@ public sealed class Circle
    {
    public double Radius { get; set; }

    public double Calculate(Func<double, double> op)
    public double Calculate(Func<double, double> operation)
    {
    return op(Radius);
    return operation(Radius);
    }
    }
  23. Clint Simon revised this gist Aug 19, 2020. 5 changed files with 18 additions and 14 deletions.
    10 changes: 5 additions & 5 deletions Q1.cs
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,15 @@
    // What is the output of the short program below? Explain your answer.

    using System;

    class Program
    public class Program
    {
    static string location = default(string);
    static DateTime time = default(DateTime);

    static void Main()
    public static void Main()
    {
    Console.WriteLine(location == null ? "location is null" : location);
    Console.WriteLine(time == DateTime.MinValue ? "time is null" : time.ToString());
    }
    }
    }

    // What is the output of the short program below? Explain your answer.
    2 changes: 1 addition & 1 deletion Q5.cs
    Original file line number Diff line number Diff line change
    @@ -19,4 +19,4 @@ public static void Main()
    printer();
    }
    }
    }
    }
    15 changes: 9 additions & 6 deletions Q6.cs
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,11 @@
    using System.Linq;

    static void Main(string[] args)
    public class Program
    {
    int[] numbers = { 30, 325, 18, 92, 100, 42, 72 };
    }

    // Use linq to find which numbers are evenly divisible by 5.
    public static void Main()
    {
    int[] numbers = { 30, 325, 18, 92, 100, 42, 72 };

    // Use linq to find which numbers are evenly divisible by 5.

    }
    }
    2 changes: 1 addition & 1 deletion Q7.cs
    Original file line number Diff line number Diff line change
    @@ -30,4 +30,4 @@ private static void DoSomething(int someNumber)
    {
    someNumber = 777;
    }
    }
    }
    3 changes: 2 additions & 1 deletion Q8.cs
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    // What is the output of the short program below? Explain your answer.

    using System;

    public class Program
    @@ -31,4 +32,4 @@ public static void Main()
    Console.WriteLine("Finally");
    }
    }
    }
    }
  24. Clint Simon revised this gist Aug 19, 2020. 6 changed files with 107 additions and 72 deletions.
    20 changes: 12 additions & 8 deletions Q1.cs
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,15 @@
    // What is the output of the short program below? Explain your answer.

    class Program {
    static string location = default(string);
    static DateTime time = default(DateTime);

    static void Main() {
    Console.WriteLine(location == null ? "location is null" : location);
    Console.WriteLine(time == DateTime.MinValue ? "time is null" : time.ToString());
    }
    using System;

    class Program
    {
    static string location = default(string);
    static DateTime time = default(DateTime);

    static void Main()
    {
    Console.WriteLine(location == null ? "location is null" : location);
    Console.WriteLine(time == DateTime.MinValue ? "time is null" : time.ToString());
    }
    }
    31 changes: 23 additions & 8 deletions Q3.cs
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,26 @@
    // Given an instance circle of the following class:
    using System;

    public sealed class Circle {
    public double Radius { get; set; }

    public double Calculate(Func<double, double> op) {
    return op(Radius);
    }
    public class Program
    {
    public static void Main()
    {
    var circle1 = new Circle {
    Radius = 1
    };

    // Given an instance of the Circle class
    // Write code to calculate the circumference of the circle (2 * pi * r)
    // without modifying the Circle class itself.

    }
    }

    // Write code to calculate the circumference of the circle (2 * pi * r), without modifying the Circle class itself.
    public sealed class Circle
    {
    public double Radius { get; set; }

    public double Calculate(Func<double, double> op)
    {
    return op(Radius);
    }
    }
    33 changes: 19 additions & 14 deletions Q4.cs
    Original file line number Diff line number Diff line change
    @@ -1,19 +1,24 @@
    // What is the output of the program below? Explain your answer.

    class Program {
    private static string _result;

    static void Main() {
    SaySomethingAsync();
    Console.WriteLine(_result);
    }

    static async Task<string> SaySomethingAsync() {
    await Task.Delay(5);
    _result = "Hello world!";
    return "Something";
    }
    using System;
    using System.Threading.Tasks;

    public class Program
    {
    private static string _result = "Nothing";

    public static void Main()
    {
    SaySomethingAsync();
    Console.WriteLine(_result);
    }

    public static async Task<string> SaySomethingAsync()
    {
    await Task.Delay(5);
    _result = "Something";
    return "SaySomething exited";
    }
    }

    // Also, would the answer change if we were to replace await Task.Delay(5); with Thread.Sleep(5)? Why or why not?

    27 changes: 16 additions & 11 deletions Q5.cs
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,22 @@
    // What is the output of the program below? Explain your answer.

    delegate void Printer();
    using System;
    using System.Collections.Generic;

    static void Main()
    public class Program
    {
    List printers = new List();
    for (int i = 0; i < 10; i++)
    {
    printers.Add(delegate { Console.WriteLine(i); });
    }
    public static void Main()
    {
    var printers = new List<Action>();

    for (int i = 0; i < 10; i++)
    {
    printers.Add(() => Console.WriteLine(i));
    }

    foreach (var printer in printers)
    {
    printer();
    }
    foreach (var printer in printers)
    {
    printer();
    }
    }
    }
    11 changes: 7 additions & 4 deletions Q7.cs
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,7 @@
    // What is the output of the short program below? Explain your answer.

    using System;

    public class Person
    {
    public string Name { get; set; }
    @@ -7,17 +11,16 @@ public class Program
    {
    public static void Main(string[] args)
    {
    Person joe = new Person();
    var joe = new Person();
    joe.Name = "Joe";

    Person tim = joe;
    var tim = joe;
    tim.Name = "tim";

    Console.WriteLine(joe.Name);
    Console.WriteLine(tim.Name);


    int myNumber = 666;
    var myNumber = 666;
    DoSomething(myNumber);

    Console.WriteLine(myNumber);
    57 changes: 30 additions & 27 deletions Q8.cs
    Original file line number Diff line number Diff line change
    @@ -1,31 +1,34 @@
    // What is the output of the short program below? Explain your answer.
    using System;

    class Program {
    static void Main() {
    try
    {
    throw new Exception("Exception 1");
    }
    catch (Exception ex)
    {
    Console.WriteLine(ex.Message);
    }
    public class Program
    {
    public static void Main()
    {
    try
    {
    throw new Exception("Exception 1");
    }
    catch (Exception ex)
    {
    Console.WriteLine(ex.Message);
    }

    try
    {
    throw new ApplicationException("Exception 2");
    }
    catch (ApplicationException ex)
    {
    Console.WriteLine("ApplicationException 2");
    }
    catch (Exception ex)
    {
    Console.WriteLine(ex.Message);
    }
    finally
    {
    Console.WriteLine("Finally");
    }
    }
    try
    {
    throw new ApplicationException("Exception 2");
    }
    catch (ApplicationException ex)
    {
    Console.WriteLine("ApplicationException 2");
    }
    catch (Exception ex)
    {
    Console.WriteLine(ex.Message);
    }
    finally
    {
    Console.WriteLine("Finally");
    }
    }
    }
  25. Clint Simon revised this gist Dec 6, 2019. 2 changed files with 32 additions and 1 deletion.
    2 changes: 1 addition & 1 deletion Q1.cs
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,6 @@ class Program {

    static void Main() {
    Console.WriteLine(location == null ? "location is null" : location);
    Console.WriteLine(time == null ? "time is null" : time.ToString());
    Console.WriteLine(time == DateTime.MinValue ? "time is null" : time.ToString());
    }
    }
    31 changes: 31 additions & 0 deletions Q8.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    // What is the output of the short program below? Explain your answer.

    class Program {
    static void Main() {
    try
    {
    throw new Exception("Exception 1");
    }
    catch (Exception ex)
    {
    Console.WriteLine(ex.Message);
    }

    try
    {
    throw new ApplicationException("Exception 2");
    }
    catch (ApplicationException ex)
    {
    Console.WriteLine("ApplicationException 2");
    }
    catch (Exception ex)
    {
    Console.WriteLine(ex.Message);
    }
    finally
    {
    Console.WriteLine("Finally");
    }
    }
    }
  26. Clint Simon revised this gist Jun 29, 2018. 3 changed files with 5 additions and 6 deletions.
    8 changes: 4 additions & 4 deletions Q4.cs
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,16 @@
    // What is the output of the program below? Explain your answer.

    class Program {
    private static string result;
    private static string _result;

    static void Main() {
    var result = SaySomethingAsync();
    Console.WriteLine(result);
    SaySomethingAsync();
    Console.WriteLine(_result);
    }

    static async Task<string> SaySomethingAsync() {
    await Task.Delay(5);
    result = "Hello world!";
    _result = "Hello world!";
    return "Something";
    }
    }
    1 change: 0 additions & 1 deletion Q6.cs
    Original file line number Diff line number Diff line change
    @@ -6,4 +6,3 @@ static void Main(string[] args)
    }

    // Use linq to find which numbers are evenly divisible by 5.

    2 changes: 1 addition & 1 deletion Q7.cs
    Original file line number Diff line number Diff line change
    @@ -16,8 +16,8 @@ public static void Main(string[] args)
    Console.WriteLine(joe.Name);
    Console.WriteLine(tim.Name);


    int myNumber = 666;

    DoSomething(myNumber);

    Console.WriteLine(myNumber);
  27. Clint Simon revised this gist Jun 29, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Q4.cs
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@ class Program {
    private static string result;

    static void Main() {
    SaySomethingAsync();
    var result = SaySomethingAsync();
    Console.WriteLine(result);
    }

  28. Clint Simon revised this gist Dec 18, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Q3.cs
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,10 @@
    // Given an instance circle of the following class:

    public sealed class Circle {
    private double radius;
    public double Radius { get; set; }

    public double Calculate(Func<double, double> op) {
    return op(radius);
    return op(Radius);
    }
    }

  29. Clint Simon revised this gist Jan 5, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Q7.cs
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ public class Person
    public string Name { get; set; }
    }

    class Program
    public class Program
    {
    public static void Main(string[] args)
    {
  30. Clint Simon renamed this gist Jan 5, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.