Answer the question
In order to leave comments, you need to log in
NullReferenceException when comparing contents of ComboBoxItem?
private void ComboBoxMenu_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ComboBoxItem lbi = ((sender as ComboBox).SelectedItem as ComboBoxItem);
if (lbi.Content.ToString()=="Вийти из приложения")
if (lbi.Content.ToString()=="Вийти из приложения")
System.NullReferenceException: "Object reference does not point to an instance of an object."
Answer the question
In order to leave comments, you need to log in
ComboBoxItem lbi = ((sender as ComboBox).SelectedItem as ComboBoxItem);
lbi
can contain null
if nothing is selected, because as
returns null
if the conversion failed. Content
y field null
. The compiler reports this. null
before uselbi
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question