TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Maha
NA
0
328k
ToString() & get()
Feb 11 2012 9:09 AM
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
*/
Reply
Answers (
2
)
Declare a class as abstract in C#
Send key to JUMP TO FILE winamp window