Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save supreettare/d74d352706f1a21abf9fd16f8b04081d to your computer and use it in GitHub Desktop.

Select an option

Save supreettare/d74d352706f1a21abf9fd16f8b04081d to your computer and use it in GitHub Desktop.
What is the output of the short program below? Explain your answer.
class Program {
static String location;
static DateTime time;
static void Main() {
Console.WriteLine(location == null ? "location is null" : location);
Console.WriteLine(time == null ? "time is null" : time.ToString());
}
}
@SaiSulochana
Copy link

location is string variable, we didn't assign any value to that variable so it will be null, it will write location is null on the console.
time will be default minvalue.

@sajijohn80
Copy link

null is the default value of reference types so the statement "location == null" evaluates to true.
time will be set to a default value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment