0

为什么即使一切都是空的,这个程序仍然输出“not null”?!我必须改变什么才能最终使它为空?

“您的帖子没有太多解释代码部分的上下文;请更清楚地解释您的场景。” 对不起……

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();
    }
}
4

2 回答 2

4

因为它已初始化,所以它不为空。

BitmapImage myBitmap = new BitmapImage();

新操作员

于 2013-01-10T22:26:28.357 回答
1

你总是得到,"not null'因为总有一些东西在里面myBitmap——毕竟,你只是创建了一个new BitmapImage()并把它放在那里!

于 2013-01-10T22:27:54.050 回答