2
Answers

ToString() & get()

Maha

Maha

12y
1.3k
1
In this example program if we replaced ToString() method by get() method same result can be obtained. So that what is the purpose of using ToString() method.

using System;
class Customer
{
protected string name;
protected double balanceDue;

public Customer()
{
name = "Maha";
balanceDue = 0;
}
}
class PreferredCustomer : Customer
{
private double discountRate;
private int sinceYear;

public PreferredCustomer()
{
discountRate = 0.08;
sinceYear = 1997;
}
public new string ToString()
{
return name + " " + balanceDue + " " + discountRate + " " + sinceYear;
}
}
class DemoPreferredCustomerConstructor2
{
public static void Main()
{
PreferredCustomer pc = new PreferredCustomer();
Console.WriteLine("The preferred customer is {0}", pc.ToString());

Console.ReadKey();
}
}
/*
The preferred customer is Maha 0 0.08 1997
*/

Answers (2)