<code>namespace SharpenYourPencil
{
internal class Elephant
{
public string Name;
public int EarSize;
public void WhoAmI()
{
Console.WriteLine($"My name is {Name}.");
Console.WriteLine($"My ears {EarSize} inches tall.");
}
}
internal class Program
{
static void Main(string[] args)
{
Elephant lucinda = new Elephant() { Name = "Lucinda", EarSize = 33 };
Elephant lloyd = new Elephant() { Name = "lloyd", EarSize = 40 };
Console.WriteLine("Press 1 for Lloyd, 2 for Lucinda, 3 to swap");
while (true)
{
char ca = Console.ReadKey(true).KeyChar;
Console.WriteLine($"You pressed {ca}.");
switch (ca)
{
case '1':
Console.WriteLine("calling Lucinda.WhoAmI()");
lucinda.WhoAmI(); break;
case '2':
Console.WriteLine("calling Lloyd.WhoAmI()");
lloyd.WhoAmI(); break;
case '3':
Elephant holder;
holder = lloyd;
lloyd = lucinda;
lucinda = holder;
Console.WriteLine("Reference have been swapped");
break;
default:
Console.WriteLine("Press 1 or 2 or 3");
break;
}
Console.WriteLine();
}
}
}
}
</code>
<code>namespace SharpenYourPencil
{
internal class Elephant
{
public string Name;
public int EarSize;
public void WhoAmI()
{
Console.WriteLine($"My name is {Name}.");
Console.WriteLine($"My ears {EarSize} inches tall.");
}
}
internal class Program
{
static void Main(string[] args)
{
Elephant lucinda = new Elephant() { Name = "Lucinda", EarSize = 33 };
Elephant lloyd = new Elephant() { Name = "lloyd", EarSize = 40 };
Console.WriteLine("Press 1 for Lloyd, 2 for Lucinda, 3 to swap");
while (true)
{
char ca = Console.ReadKey(true).KeyChar;
Console.WriteLine($"You pressed {ca}.");
switch (ca)
{
case '1':
Console.WriteLine("calling Lucinda.WhoAmI()");
lucinda.WhoAmI(); break;
case '2':
Console.WriteLine("calling Lloyd.WhoAmI()");
lloyd.WhoAmI(); break;
case '3':
Elephant holder;
holder = lloyd;
lloyd = lucinda;
lucinda = holder;
Console.WriteLine("Reference have been swapped");
break;
default:
Console.WriteLine("Press 1 or 2 or 3");
break;
}
Console.WriteLine();
}
}
}
}
</code>
namespace SharpenYourPencil
{
internal class Elephant
{
public string Name;
public int EarSize;
public void WhoAmI()
{
Console.WriteLine($"My name is {Name}.");
Console.WriteLine($"My ears {EarSize} inches tall.");
}
}
internal class Program
{
static void Main(string[] args)
{
Elephant lucinda = new Elephant() { Name = "Lucinda", EarSize = 33 };
Elephant lloyd = new Elephant() { Name = "lloyd", EarSize = 40 };
Console.WriteLine("Press 1 for Lloyd, 2 for Lucinda, 3 to swap");
while (true)
{
char ca = Console.ReadKey(true).KeyChar;
Console.WriteLine($"You pressed {ca}.");
switch (ca)
{
case '1':
Console.WriteLine("calling Lucinda.WhoAmI()");
lucinda.WhoAmI(); break;
case '2':
Console.WriteLine("calling Lloyd.WhoAmI()");
lloyd.WhoAmI(); break;
case '3':
Elephant holder;
holder = lloyd;
lloyd = lucinda;
lucinda = holder;
Console.WriteLine("Reference have been swapped");
break;
default:
Console.WriteLine("Press 1 or 2 or 3");
break;
}
Console.WriteLine();
}
}
}
}
“Here is what happens when I compile it.”
***Press 1 for Lloyd, 2 for Lucinda, 3 to swap
You pressed 1.
calling Lucinda.WhoAmI()
My name is Lucinda.
My ears 33 inches tall.
.ou pressed
Press 1 or 2 or 3***
“I want to know what the problem is.”
New contributor
yooth5671 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.