Reputation: 5
why this program still output "not null" even if everything is empty?! What do i have to change to finally make it null?
"Your post does not have much context to explain the code sections; please explain your scenario more clearly." Sorry for that...
public interface IDrawable
{
void Draw();
}
public interface IAdvancedDraw : IDrawable
{
void DrawInBoundingBox();
void DrawUpsideDown();
}
public class BitmapImage : IAdvancedDraw
{
public void Draw() { }
public void DrawInBoundingBox() { }
public void DrawUpsideDown() { }
}
class Program
{
static void Main( string[] args )
{
BitmapImage myBitmap = new BitmapImage();
if ((IAdvancedDraw)myBitmap != null){
Console.WriteLine("not null");
}
Console.ReadLine();
}
}
Upvotes: 0
Views: 82
Reputation: 13696
You're always getting "not null'
because there's always something in myBitmap
- after all, you just created a new BitmapImage()
and put it there!
Upvotes: 1
Reputation: 460058
Because it is initialized it is not null.
BitmapImage myBitmap = new BitmapImage();
Upvotes: 4