我有这个C#代码用于填充手机屏幕上的标签.请注意,这里不使用HTML源代码.
c1Label.Text = "To select cards for your deck you can one of a number of options •
Run Code Online (Sandbox Code Playgroud)
和这个XAML
<local:JustifiedLabel x:Name="c1Label" Text= "To select cards for your deck you can one of a number of options •
Run Code Online (Sandbox Code Playgroud)
前者显示 作为文本的一部分,但XAML版本工作正常并将其显示为换行符后跟子弹.
我有这个SQL查询?
SELECT COUNT(*) FROM PHRASE WHERE JLPT = 1
SELECT COUNT(*) FROM PHRASE WHERE JLPT = 2
SELECT COUNT(*) FROM PHRASE WHERE JLPT = 3
SELECT COUNT(*) FROM PHRASE WHERE JLPT = 4
Run Code Online (Sandbox Code Playgroud)
有没有办法可以将这些查询合并为1,以便计算出有多少JLPT行的值为1,2,3和4?
我正在使用此代码:
query = String.IsNullOrEmpty(options.PhraseNum) ?
query :
query.Where(w => w.PhraseNum == Convert.ToInt32(options.PhraseNum));
Run Code Online (Sandbox Code Playgroud)
但是我收到一个错误:
LINQ to Entities无法识别方法'Int32 ToInt32(System.String)'方法,并且此方法无法转换为存储表达式.
有没有办法可以在LINQ中执行此操作,如果不能,我如何在此之外进行转换并且如果字符串不为null,则转换不会导致异常?
我有一个变量:
public static List<CardSetWithWordCount> cardSetWithWordCounts;
Run Code Online (Sandbox Code Playgroud)
班级看起来像这样;
public class CardSetWithWordCount
{
public int Id { get; set; }
public string Name { get; set; }
public bool IsToggled { get; set; }
public int TotalWordCount { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我该如何检查:
我正在考虑LINQ,因为我以前使用过它,但我不确定LINQ可以进行这种级别的检查.我有兴趣看看是否有人知道它是否可能,或者我只需要编写forEach循环或其他一些构造.任何提示将非常感激.
如何在XAML中设置标签的可见性,以便在该标签的Text属性不为null时变为可见?
我有这个代码:
<Label Grid.Row="0" Text="*" IsVisible="emptyLabel1 == null"/>
<Label Grid.Row="0" Text="{Binding EmptyLabel1}" IsVisible="emptyLabel1 == null"/>
<Label Grid.Row="1" Text="*" IsVisible="emptyLabel2 == null"/>
<Label Grid.Row="1" Text="{Binding EmptyLabel2}" IsVisible="emptyLabel2 == null"/>
Run Code Online (Sandbox Code Playgroud)
在我的VM中它看起来像这样:
private string emptyLabel1;
private string emptyLabel2;
public string EmptyLabel1
{
get { return emptyLabel1; }
set
{
if (value != emptyLabel1)
{
emptyLabel1 = value;
NotifyPropertyChanged("EmptyLabel1");
}
}
}
public string EmptyLabel2
{
get { return emptyLabel2; }
set
{
if (value != emptyLabel2)
{
emptyLabel2 = value;
NotifyPropertyChanged("EmptyLabel2");
}
} …Run Code Online (Sandbox Code Playgroud) 我有这个字符串:
var a = "a new test string today";
Run Code Online (Sandbox Code Playgroud)
我如何解析一个只包含单词的另一个字符串
"a new test"
Run Code Online (Sandbox Code Playgroud) 如果我有这样的方法:
private void RunExecute()
{
var rc1 = doStuff(2);
var rc2 = doStuff(1);
}
Run Code Online (Sandbox Code Playgroud)
有什么方法可以返回 rc1 和 rc2 而不是 void,而无需创建特殊类并将其用作返回类型,并且无需将 rc1 和 rc2 声明为输出参数?
我有这个代码:
public static List<Phrase> selectedPhrases;
Run Code Online (Sandbox Code Playgroud)
和
if (!App.selectedPhrases.Any(x => x.Viewed == false))
return;
Run Code Online (Sandbox Code Playgroud)
有什么方法可以改变我声明 selectedPhrases 的方式,以便我可以以这种方式进行最后一次检查:
if (App.selectedPhrases.AllViewed())
return;
Run Code Online (Sandbox Code Playgroud)
我听说过扩展方法,但是可以像在我的代码中那样为 List 创建一个方法吗?
我有以下代码:
foreach (var node in nodes)
{
result += node.InnerText;
}
Run Code Online (Sandbox Code Playgroud)
该InnerText仅仅是1-2个字符,永远不会包含#符号。节点中可以有一个或多个node值。
我如何分隔每个元素,例如,如果这些是node的值:
"ab" and "cd"
Run Code Online (Sandbox Code Playgroud)
结果将是ab#cd。
我知道我可以添加#值,但是最后一个字符呢。如果我只是简单地添加,#那么我会得到ab#cd#不是我想要的。
我有此代码可以工作,但我想简化一下。我试图将每个.ForEach串在一起,但似乎不可能。有人可以建议我如何结合这些:
phraseSources
.ToList()
.ForEach(i => i.JishoExists = "");
phraseSources
.ToList()
.ForEach(i => i.CommonWord = "");
phraseSources
.ToList()
.ForEach(i => i.JishoWanikani = null);
phraseSources
.ToList()
.ForEach(i => i.JishoJlpt = null);
Run Code Online (Sandbox Code Playgroud)