如何使用JavaScript循环遍历数组中的所有条目?
我以为它是这样的:
forEach(instance in theArray)
Run Code Online (Sandbox Code Playgroud)
theArray
我的阵列在哪里,但这似乎是不正确的.
在WPF中,我有一个包含几列的DataGrid.
默认情况下,有1我想让它排序,但我不知道如何做到这一点.
XAML中的DataGrid如下所示:
<DataGrid x:Name="LibraryView" ItemsSource="{Binding Path=Elements[Persons]}" IsReadOnly="True" LoadingRow="dg_LoadingRow">
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Binding="{Binding Path=Element[Name].Value}" IsReadOnly="True" />
<DataGridTextColumn Header="Score" Binding="{Binding Path=Element[Score].Value}" IsReadOnly="True" />
<DataGridTextColumn Header="Date" Binding="{Binding Path=Element[Date].Value}" IsReadOnly="True" />
</DataGrid.Columns>
</DataGrid>
Run Code Online (Sandbox Code Playgroud)
它背后唯一的代码是:
public ScoreBoard()
{
InitializeComponent();
DataSet ds = dweMethods.DecryptAndDeserialize("ScoreData.xml");
XElement TrackList = XElement.Parse(ds.GetXml());
LibraryView.DataContext = TrackList;
}
Run Code Online (Sandbox Code Playgroud)
我找不到的是默认情况下如何按"分数"列进行排序.
任何人都可以帮我指出正确的方向吗?
我试图做的是生成随机int值的数组,其中随机值在min和max之间取得.
到目前为止,我想出了这段代码:
int Min = 0;
int Max = 20;
int[] test2 = new int[5];
Random randNum = new Random();
foreach (int value in test2)
{
randNum.Next(Min, Max);
}
Run Code Online (Sandbox Code Playgroud)
但它还没有完全发挥作用.我想我可能只缺少1行或其他东西.任何人都可以帮我推动我朝着正确的方向前进吗?
在WPF应用程序中,我有一个包含很多字段的窗口.当用户在填充每个字段后使用TAB键时,Windows会理解它会移动到下一个字段.这是非常了解的行为.
现在我想要的是,它使模拟TAB键,实际上RETURN被击中.所以在我的WPF xaml中,我添加了暗示KeyDown="userPressEnter"
在它背后的代码中:
private void userPressEnter(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return)
{
e.Key = Key.Tab // THIS IS NOT WORKING
}
}
Run Code Online (Sandbox Code Playgroud)
现在,显然这不起作用.但我不知道的是,我如何使这项工作?
编辑1 ==>找到一个解决方案
我找到了帮助我的东西=)
private void userPressEnter(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return)
{
TraversalRequest request = new TraversalRequest(FocusNavigationDirection.Next);
MoveFocus(request);
}
}
Run Code Online (Sandbox Code Playgroud)
这样,焦点移动到下一个它可以找到:)
(使用WPF)我试图检测何时Ctrl+ Enter被击中.所以我尝试了这段代码:
if (e.Key == Key.Return && (e.Key == Key.LeftCtrl || e.Key == Key.RightCtrl))
{
//Do Something
}
Run Code Online (Sandbox Code Playgroud)
显然这是不正确的,因为它不起作用.任何人都可以帮助我,解释正确的方法应该是什么?
感谢名单
只是我想知道的事情.在欧洲,逗号我们主要用于小数(如20,001)但在欧洲以外的地方主要使用(如20.001)c#如何处理这个?如果应用程序将由欧洲和非欧洲人使用,编程时是否需要担心上述问题?
只是好奇这个.
我在我的应用程序中遇到此问题:
我的第一个问题是这部分代码:
XmlDocument xmlDoc = new XmlDocument();
DataSet ds = //use a method to put in the data
xmlDoc.LoadXml(ds.GetXml());
xmlDoc.Save("Filename");
// ...
Process.Start(startInfo);
Run Code Online (Sandbox Code Playgroud)
我的假设是否正确,只有在完成上述操作后才会执行最后一行?所以我可以100%确定数据是否都在xml中,然后才能尝试启动它?
我现在收到错误的第二部分是:
Process.Start(startInfo);
File.Delete("Filename");
Run Code Online (Sandbox Code Playgroud)
现在发生的事情是,在第三方程序将文件读入其内存之前,该文件已被删除.
有什么方法可以检查文件不再使用,或者做一些稳定的等待方式?
我已经找到了一种使用方法,Thread.Sleep(TimeInMiliSec);
但我想这不是一种正确的方法(更像是一种解决方案)?
As i am not very advanced in C# yet, I try to learn how to make my code more efficient. I stored a lot of strings in some of the properties.
At the start of the application, i load all the seperatie properties into the textboxes. I now ise this code to load them all:
private void LoadStoredStrings()
{
txtT1S1.Text = Properties.Settings.Default.strT1L1;
txtT1S2.Text = Properties.Settings.Default.strT1L2;
txtT1S3.Text = Properties.Settings.Default.strT1L3;
txtT1S4.Text = Properties.Settings.Default.strT1L4;
txtT1S5.Text = Properties.Settings.Default.strT1L5;
txtT1S6.Text = Properties.Settings.Default.strT1L6;
txtT1S7.Text = Properties.Settings.Default.strT1L7; …
Run Code Online (Sandbox Code Playgroud) 我还在C#学习,有一件事我似乎无法找到答案.
如果我有一个看起来像这样的字符串"abcdefg012345",我想让它看起来像"ab-cde-fg-012345"
我想这样的事情:
string S1 = "abcdefg012345";
string S2 = S1.Insert(2, "-");
string S3 = S2.Insert(6, "-");
string S4 = S3.Insert.....
...
..
Run Code Online (Sandbox Code Playgroud)
现在我正在寻找是否有可能以某种方式将这个al变成1行,而不必制作所有这些字符串.
我认为这可能以某种方式?
我的项目中有以下字符串:
((1,01/31/2015)(1,Filepath)(1,name)(1,code)(1,String)(1, ))
我想将此字符串分成几个部分,在这些部分中我可以获取捕获括号内的信息(例如1,Filepath
or (1,Filepath)
,但整个字符串也位于捕获括号中,如您所见。然后我尝试将结果放入数组中string[] array = Regex.Split(originalString,SomeRegexHere)
现在我想知道最好的方法是什么,只需删除字符串的第一个和最后一个字符,这样我就没有捕获整个字符串的括号,或者是否有某种方法可以在此使用正则表达式来获取我想要的结果是?