+ 4
Tricky Q on value types & ref types.. guess o/p
class Program { static String theLocation; static DateTime theTime; static void Main() { Console.WriteLine(theLocation == null ? "theLocation is null" : theLocation); Console.WriteLine(theTime == null ? "theTime is null" : theTime.ToString()); } }
9 Respostas
+ 2
What is your question ?
+ 2
what will be the output and its explanation
+ 2
The output will be :
theLocation is null
theTime is null
It will be like this because you did not initialize them and C# use null as default value for classes instance.
+ 2
@prunier
there will default date time in output
as datetime value types
try to run that code
+ 2
theTime is a value type. As such, an uninitialized DateTime. variable is set to the default value of midnight on 1/1/1. the year 1 A.D
+ 2
because for that i was confused
i was searching its reason so i put this w simultaneously here too
+ 2
Okay, I hope I helped even if my answer had mistakes :)
+ 1
I tried and it seems so, I did not know that :)
+ 1
Yeah, I know that value type have default values other than null. But if you know the answer, then why did you ask the question in the first time ? ^^