I want to return a date in the UK format, rather than the US format that it currently stored.
Therefore, I decided to add a getter and setter to the value within my class.
However, when I run the code with a getter and setter in place, the page fails to load.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
// Globalisation for converting dates from American to British format
using System.Globalization;
/// <summary>
/// Class to hold the summary of an order take from database TOEHEAD
/// </summary>
public class OrderSummary
{
public string order_number { get; set; }
public string order_date
{
get
{
try
{
string ukDateTimeFormat = Convert.ToString(DateTime.Parse(this.order_date, CultureInfo.CreateSpecificCulture("en-US")));
return ukDateTimeFormat;
}
catch (FormatException e)
{
return "Error";
}
}
set
{
this.order_date = value;
}
}
public string order_total { get; set; }
public OrderSummary()
{
}
}
If I put this code in to a function and return it that way, it works fine.
Have I formatted something wrong?
You cause a Stack Overflow by calling the same property from your get code
You do this also in the
setFixed code: