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