I have a question regarding the design of the Date object in the .Net framework, more specifically the Now property.
I know that Now is a property that is a Date type. (This makes sense since I see the methods .AddHours(), AddYears(), etc) If Now being a class(or struct) how does it return a value directly.
For example: How would I create a class or struct in C#/VB.net that would allow me to do the same without calling a property of Now?
(VB.Net)
Dim WeatherObject as new WeatherReporter()
If WeeatherReport had a property called TodaysWeather that was a class how could I then get a value like this
Dim PlainTextReport as string=WeeatherReport.TodaysWeather
To me it seems like you would have to call a another property off of TodaysWeather. But with the Datetime.Now example you don’t. Anyways, I know its an odd question. I was just trying to better understand how some of these objects are set up under the hood
Thanks for any light on the matter.
Here is an example of code referring to the above question.
Public Class WeatherReporter
Shared ReadOnly Property TodaysWeather As DayWeather
Get
TodaysWeather = New DayWeather
Return TodaysWeather.Current
End Get
End Property
End Class
Public Class DayWeather
Public Property Current As String = "Sunny"
End Class
Now similar to the DateTime.Now object
How could one you the weather example like this
Dim TheForecast as string=WeatherReporter.TodaysWeather
It seems like it would require the following
Dim TheForecast as string=WeatherReporter.TodaysWeather.Current
I know its a confusing question, lol. thanks for your patience
DateTime.Nowlooks something like this in VB.net…or in C#: