In this program keyword override is not used. In my view ToString() method is not used therefore override is not used. I wish to know whether my understanding is correct. Problem is highlighted.
http://msdn.microsoft.com/en-us/library/ms173116.aspx
using System;
class Person
{
// Copy constructor.
public Person(Person previousPerson)
{
Name = previousPerson.Name;
Age = previousPerson.Age;
}
//// Alternate copy constructor calls the instance constructor.
//public Person(Person previousPerson)
// : this(previousPerson.Name, previousPerson.Age)
//{
//}
// Instance constructor.
public Person(string name, int age)
{
Name = name;
Age = age;
}
public int Age { get; set; }
public string Name { get; set; }
public string Details()
{
return Name + " is " + Age.ToString();
}
}
class TestPerson
{
static void Main()
{
// Create a Person object by using the instance constructor.
Person person1 = new Person("George", 40);
// Create another Person object, copying person1.
Person person2 = new Person(person1);
// Change each person's age.
person1.Age = 39;
person2.Age = 41;
// Change person2's name.
person2.Name = "Charles";
// Show details to verify that the name and age fields are distinct.
Console.WriteLine(person1.Details());
Console.WriteLine(person2.Details());
// Keep the console window open in debug mode.
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}
// Output:
// George is 39
// Charles is 41
Loading

VulpesPosted Dec 4, 2014, 5:48 AM
There's no override of the ToString() method which is perhaps the commonest way in which an object can provide details of itself.
MahaPosted Dec 4, 2014, 5:55 AM
Vikram AgrawalPosted Dec 4, 2014, 5:49 AM
In your code everything is right and output is also same as expected. so tell me what is doubt you have regarding this code?
Do you want to override the ToString() method in this code?