Just like a little game of guessing went, I want to present you another C# riddle
:
using System;
namespace AnotherRiddle
{
internal class Program
{
static void Main(string[] args)
{
var w1 = new Wee { bar = new Foo() };
if (w1.bar is Bar)
Console.WriteLine("A");
if (w1.bar.GetType() == typeof(Bar))
Console.WriteLine("B");
}
}
internal class Bar { }
internal class Foo : Bar { }
internal class Wee
{
public Bar bar;
}
}
1. What do you think the code snippet will print at the console?
2. What are all the differences between the two if constructs?
4919d78e-5523-42db-938a-22e77fe33a6c|1|5.0
Let's say I have this block of C# code that compiles
if (someVariable == true)
{
// do something
}
but in a haste to optimize the code I change it into :
if (someVariable)
{
// do something
}
and suddenly my code does not compile anymore.
WHAT TYPE COULD someVariable HAVE?! Please comment on what you think about this small riddle :)
ef24bbc6-6b9f-4b80-b573-5e10e8161324|6|3.0