Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

[C#] Override ToString method #1 isn't necessary Here is my code: class Overriding_ToString { public void RunExercise() { MyPoint p = new MyPoint(3, 7.6); Console.WriteLine(Your

[C#] Override ToString method

#1 isn't necessary

image text in transcribed

Here is my code:

class Overriding_ToString { public void RunExercise() { MyPoint p = new MyPoint(3, 7.6); Console.WriteLine("Your point is at:" + p.ToString()); Console.WriteLine("Your point is at:{0}", p.ToString()); Console.WriteLine("Your point is at:" + p); Console.WriteLine("Your point is at:{0}", p); } }

1. Look up (either in Visual Studio's online help, or msdn.com) the Object class. Read the description, and skim through the methods & any properties it might have A. Read through the ToString method in detail 2. Compile and run the code provided to you in Overriding_ToString.RunExercise), and note the output. You may want to copy the output someplace so that you can compare it against the end result' output you'll get later 3. In the provided starter project, in the file named Program.cs you can find the MyPoint class; you will note that part of it has already been written for you. You need to correctly override the ToString method. This should work pretty much the same as any other exercise around polymorphism - the only real difference is that instead of you defining the base class, Microsoft has already done that for you. A. Hint: Your ToString method must have the same signature and return type as the one defined in the Object class that you looked up online. B. Hint: The ONLY code that you write for this exercise should be to add the properly overridden ToString method to the MyPoint class, and nothing else C. Hint: When you're done the output from the in Overriding_ToString.RunExercise) method should similar to the following (Your output does not need to be exactly the same, but it should be able to print numbers with decimal places) Your point is at: (3.0,7.6) Your point is at: (3.0,7.6) Your point is at: (3.0,7.6) Your point is at: (3.0,7.6)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions