jimgreener
New member
- Joined
- Nov 22, 2017
- Messages
- 1
- Programming Experience
- Beginner
I am new to programming...I came across this code...I am not clear what it does - Can someone help :
Sorry if I posted the wrong question to wrong forum -
Sorry if I posted the wrong question to wrong forum -
public class TimeSlot { public ushort Time { get; set; } public TimeSlot(ushort val) { Time = val; } public TimeSlot(string time) { ushort uTime; if (ushort.TryParse(time, out uTime)) { Time = ushort.Parse(removeAllWhiteSpaces(time)); } else throw new ArgumentException($"Invalid Format of Time slot; Use hh:mm am| hh:mm pm"); } public static TimeSlot CreateTimeSlot(string time) { return new TimeSlot(time); } private string removeAllWhiteSpaces(string str) { str = str.Trim(); str = str.Replace(" ", ""); str = str.Replace(":", ""); str = str.Replace("AM", ""); str = str.Replace("am", ""); str = str.Replace("Am", ""); str = str.Replace("aM", ""); str = str.Replace("PM", ""); str = str.Replace("pm", ""); str = str.Replace("Pm", "");\ str = str.Replace("pM", ""); return str; } }
Last edited by a moderator: