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,
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,
using System; | |
public class Program | |
{ | |
static string location = default(string); | |
static DateTime time = default(DateTime); | |
public static void Main() | |
{ | |
Console.WriteLine(location == null ? "location is null" : location); | |
Console.WriteLine(time == DateTime.MinValue ? "time is MinValue" : time.ToString()); | |
} | |
} | |
// What is the output of the short program below? Explain your answer. |
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. | |
} | |
} |
// What is the output of the program below? Explain your answer. | |
using System; | |
using System.Collections.Generic; | |
public class Program | |
{ | |
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(); | |
} | |
} | |
} |
// What is the output of the program below? Explain your answer. | |
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? |
// 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(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; | |
} | |
} |
// 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); | |
} | |
try | |
{ | |
throw new ApplicationException("Exception 2"); | |
} | |
catch (ApplicationException ex) | |
{ | |
Console.WriteLine("ApplicationException 2"); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} | |
finally | |
{ | |
Console.WriteLine("Finally"); | |
} | |
} | |
} |
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); | |
} | |
} |
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); | |
} | |
} |