Question: Create a C# console project in JetBrains Rider or Visual Studio Code and name it a2b_9. Create a file called LoneleyNumbers.cs and copy this code

Create a C# console project in JetBrains Rider or Visual Studio Code and name it a2b_9. Create a file called LoneleyNumbers.cs and copy this code into it.

namespace Lonely;

class OneLonelyNumber {

private int a = 0;

public int A {

get => a;

set { if (value > a) a = value;

} } }

class TwoLonelyNumbers : OneLonelyNumber {

private int b = 0;

public int B {

get => b;

set { if (value > b) b = value; } } }

Copy the following code into Program.cs.

using Lonely;

var aray = new OneLonelyNumber[10];

Random random = new Random();

for (int i = 0; i

if (random.Next(2) >= 1) {

aray[i] = new OneLonelyNumber();

aray[i].A = random.Next(10);

} else {

var tln = new TwoLonelyNumbers();

tln.A = random.Next(10);

tln.B = random.Next(20);

aray[i] = tln; } }

Write the code that traverses aray, outputing the values values in A and, if possible, B contained in each element. Place the output for each element on a line by itself.

Example run:

9

1 9

1

5

6

4

0 16

1

9

0

5 18

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!