为什么即使一切都是空的,这个程序仍会输出“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();
}
}
答案 0 :(得分:4)
答案 1 :(得分:1)
你总是得到"not null'
,因为myBitmap
中总是 - 毕竟,你刚刚创建了一个new BitmapImage()
并把它放在那里!