Cinchoo – ChoObject.ToString(), Part 2

In case where you want to provide your own string represent for a type, you can do so by overriding ToString() method. Cinchoo framework will use that overload and skip its own implementation to get the string represent of the type.

public class Security : ChoObject
{
    public string Symbol;
    public string CompanyName;
    public double Price;

    public Security(string symbol, string companyName, double price)
    {
        Symbol = symbol;
        CompanyName = companyName;
        Price = price;
    }

    public override string ToString()
    {
        return String.Format("Symbol: {0}, Company: {1}, Price: {2}", Symbol, CompanyName, Price);
    }
}
static void Main(string[] args)
{
    try
    {
        Security security = new Security("AAPL", "Apple Inc", 457.25);
        Console.WriteLine(security.ToString());
    }
    finally
    {
        ChoAppDomain.Exit();
    }
}

The output will be

Symbol: AAPL, Company: Apple Inc, Price: 457.25

Press any key to continue . . .

Happy coding!!!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s