Question: In C#: Start a new Visual Studio solution, a console project using .NET Core After the closing } of the class Program, write a new
In C#:
Start a new Visual Studio solution, a console project using .NET Core
After the closing } of the class Program, write a new class called Fruit.
Define 2 properties for the Fruit,
An int property called Weight
A string property called Color
You can do that using either a full, long form property or the short form
Define a Constructor that takes in 2 arguments, an int and a string and uses those values to set the 2 properties. Use this code
public Fruit(int pWeight, string pColor)
{ Weight = pWeight;
Color = pColor;
}
Now go to the Main method in the Program class, and create 3 Fruit objects.
Make the first one 10 and Red
The second one 15 and Green
The third one 7 and Yellow
Now that you have 3 Fruit objects, add 3 Console.WriteLine(), one for each Fruit object,
Each one should write out to the console
Console.WriteLine("Fruit one weights {0} and its color is {1} ", xxxx, yyyy);
Where xxx and yyy are the objects 2 properties such that what the output of the program will look like is:
Fruit one weights 10 and its color is Red
Fruit two weights 15 and its color is Green
Fruit three weights 7 and its color is Yellow
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
