简体   繁体   English

为什么该程序仍然输出“ not null”?

[英]why this program still output “not null”?

why this program still output "not null" even if everything is empty?! 为什么即使所有内容为空,该程序仍然输出“ not null”? 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();
    }
}

Because it is initialized it is not null. 因为已初始化,所以它不为null。

BitmapImage myBitmap = new BitmapImage();

new Operator 新运营商

您总是得到"not null'因为myBitmap总有东西 -毕竟,您只是创建了一个new BitmapImage()并将其放在那里!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM