user1968256
user1968256

Reputation: 5

why this program still output "not null"?

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

Answers (2)

Bobson
Bobson

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

Tim Schmelter
Tim Schmelter

Reputation: 460058

Because it is initialized it is not null.

BitmapImage myBitmap = new BitmapImage();

new Operator

Upvotes: 4

Related Questions