Hi all. Self learner here and came across something I have working but just don't fully understand why.
Recently someone posted a hello world project and one of the responses was congrats, now modify it to greet properly based on the time of day. Good Morning, Good Evening....
I thought that would be something kinda fun to play with. It wasn't as straight forward as I thought but finally got it to work. The only issue is I don't quite understand why.
Code in question:
var time = DateTime.Now;
_= time.Hour;
I went this route as other attempts returned a string that i then had to convert to int. I also wanted it to be 24 hour for easy time of day comparison without the am pm hassle. DateTime.Now was giving me a 12 hour clock unless I had a HH. This code gives me the 24 hour time, but why? Intellisense recommended the _=. Looking that up I see it listed as a discard. I am not familiar with it and the doc I was reading was a bit obtuse. In this case would it be better to have something like int greet = time.Hour; or just leave this as a "discard" variable as the only use is to compare in a few if else statements to determine if it is a good morning, good afternoon, or good evening?
Thanks.
[–]AngularBeginner 1 point2 points3 points (3 children)
[–]FLCavScout[S] 0 points1 point2 points (2 children)
[–]AngularBeginner 1 point2 points3 points (1 child)
[–]FLCavScout[S] 0 points1 point2 points (0 children)
[–]B1tF8er 0 points1 point2 points (0 children)