faster and more effective way changing date format

I have a list of users of which I want to change the Date format.

public class UserData
{
    public string DateAdded { get; set; }
}

private void FormatDateResult(List<UserData> users)
{
    foreach (var v in users.ToList())
    {
        if (v.DateAdded != null)
        {
            string temp = v.DateAdded.ToString();
            DateTime dAdded = DateTime.Parse(temp);
            v.DateAdded = dAdded.ToString("dd-MM-yyyy");
        }
    }
}

With allot of users it tends to be a bit sluggish. How can I do this in a better way?

Answers


Maybe something like this looks better

public string DateAdded { get; set; }
public string FormattedDateAdded => DateAdded != null ? DateTime.Parse(DateAdded).ToString("dd-MM-yyyy") : DateAdded;

then you can use UserData.FormattedDateAdded anywhere you want


Need Your Help

How to get the information out of a listview

c# asp.net listview

I want to extract the information from my listview. I don't know how to do this.

Revmob iOS fullscreen ad error

ios revmob

When I try to test the fullscreen ad on iOS simulator, the ad loads perfectly, but when I click it I get this error and the ad closes so I am not getting any clicks: