I have C# method:
public class HeaderType1BoolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var s = value as int;
var ret = (s == 3);
return !ret;
}
}
What I need to do is to take that object (which will be an integer), check if its value is 3 and if so return true. Otherwise if it's null or not equal to 3 then I want to return false.
But I am having a problem as it says that
Error CS0077: The as operator must be used with a reference type or nullable type ('int' is a non-nullable value type) (CS0077) (Japanese)
Can someone give me advice on how I can do this check?
as
if you know it's an int ? Also, the exception is straight forward you useas
operator to dotry to convert
since we don't know what the object might be, weather it has atry to convert method
there's theas
operator, however int has atryparse
emthod, which you can use.is
operator to check the type ofvalue
?