我有以下XAML:
<TextBlock Text="{Binding Source={x:Static s:DateTime.Now}, StringFormat=Date: {0:dddd, MMMM dd}}"/>
Run Code Online (Sandbox Code Playgroud)
s:DateTime.Now与xmlns:s="clr-namespace:System;assembly=mscorlib"在运行时,以及在设计模式(Visual Studio的2015年企业)优秀作品.
但是,如果我尝试相同CultureInfo.CurrentCulture,那么这只在运行时工作,并在设计模式(xmlns:c="clr-namespace:System.Globalization;assembly=mscorlib")中给我一个错误:
<TextBlock Text="{Binding Source={x:Static s:DateTime.Now}, ConverterCulture={x:Static c:CultureInfo.CurrentCulture}, StringFormat=Date: {0:dddd, MMMM dd}}"/>
Run Code Online (Sandbox Code Playgroud)
我不是在寻找一种解决方法.我只是想了解之间的差异DateTime.Now和CultureInfo.CurrentCulture为什么他们的作品之一,另一个没有.
假设我有一组objs不同类型的对象,我想检查是否至少有一个具有指定类型的项目MyType。什么解决方案更好?
解决方案1:
bool found = objs.OfType<MyType>().Any();
Run Code Online (Sandbox Code Playgroud)
解决方案2:
bool found = objs.Any(o => o is MyType);
Run Code Online (Sandbox Code Playgroud)
有什么区别吗?
这个问题不仅适用于 Any(),也适用于其他 LINQ 方法。