1. Course
  2. OOP
  3. Constructors and destructors

Constructors and destructors


Last updated: 8/23/2020 Difficulty: Intermediate

Create a C# program that prompts the user for three names of people and stores them in an array of Person-type objects. To do this, first create a Person class that has a Name property of type string, a constructor that receives the name as a parameter, a destructor that assigns the name to empty and overwrites the ToString () method.

End the program by reading the people and executing the ToString () method on screen.

Input

Juan
Sara
Carlos

Output

Hello! My name is Juan
Hello! My name is Sara
Hello! My name is Carlos

Solution

OOP

2 / 8

Android App


Practice C# anywhere with the free app for Android devices.

Android App

Exercises C# by difficulty


Learn C# at your own pace, the exercises are ordered by difficulty.

Make a donation


Your donations support our work and contribute to the maintenance of the app.

Advertising