-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem1.cs
More file actions
43 lines (33 loc) · 962 Bytes
/
Problem1.cs
File metadata and controls
43 lines (33 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System.Diagnostics;
/// <summary>
/// C# technical interview problem #1
/// </summary>
public static class Problem1
{
/// <summary>
/// This problem is supposed to swap two integers, a and b. Unfortunately, the end result isn't right.
/// The values aren't swapped. Fix the issue and explain why it didn't initially work. Leave the return value
/// for Swap as void.
/// </summary>
public static void SwapIntegers()
{
int a = 5;
int b = 10;
int aExpected = 10;
int bExpected = 5;
Console.WriteLine($"Before Swap: a = {a}, b = {b}");
Swap(a, b);
Console.WriteLine($"After Swap: a = {a}, b = {b}");
Debug.Assert(a == aExpected);
Debug.Assert(b == bExpected);
}
/// <summary>
/// Supposedly swaps two integers.
/// </summary>
static void Swap(int a, int b)
{
int temp = a;
a = b;
b = temp;
}
}