我如何将一个BitmapSource对象放入一个数组中而不在函数作用域之外将其变为null?

时间:2019-04-01 18:19:58

标签: c# wpf image null nullreferenceexception

简单地说...

//This part will convert pounds to kilograms
double kiloGram = bodyWeight / 2.205;

// This part will convert inches to cm
double meters = height * 2.54 / 100; // <-- we care about the height in meters

//This part will calculate the bmi using the BMI equation
double bmiResult = kiloGram / (meters * meters); // <-- only one bmiResult variable

// This part will see the correlation of BMI to healthiness
if (bmiResult < 18.5) {
    y = "you are underweight according to your BMI.";
} else if (bmiResult <= 25) { // <-- more concise if + else if
    y = "you are nomal weight according to your BMI.";
} else if (bmiResult <= 30) {
    y = "you are overweight according to your BMI.";
} else {
    y = "you are obese according to you BMI.";
}

我希望在调用Refresh()时bg不为null。我捕获了所有相关的异常,除了bg为null之外,在这种情况下,我不希望程序执行时bg为null。

1 个答案:

答案 0 :(得分:0)

在这种情况下,调用Array.Append(object)是导致我出现问题的原因。我不知道它是干什么的,但是我(错误地)认为它将对象附加到任何数组的末尾。

我用以下内容替换了这一行,并且我的代码功能达到了预期。

CREATE TABLE 01_01_01(t INT);
ALTER TABLE 01_01_01
DROP COLUMN t;