[英]How can I define variables that are not used like types?
我有一个用 Visual Studio 2017 编写的代码。
现在我正在尝试使用 Visual Studio 2015,但元组安装失败。
所以我在不使用元组的情况下编码。
这段代码
namespace TEST00
{
public class Class1<T> : IValueConverter
{
public T ValueForTrue { get; set; }
public T ValueForFalse { get; set; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool v = new bool();
bool v1 = (value is v) && v;
return v1 ? ValueForTrue : ValueForFalse;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
原因
CS0118:“v”是一个变量,但用作类型
Visual Studio 2017 中的原始代码是
namespace TEST00
{
public class Class1<T> : IValueConverter
{
public T ValueForTrue { get; set; }
public T ValueForFalse { get; set; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return ((value is bool v) && v) ? ValueForTrue : ValueForFalse;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
它有效。
我不知道如何定义“v”。
如何定义不像类型那样使用的变量?
你正在寻找这个:
bool v1 = (value is bool) && (bool)value;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.