我想使用C#删除本地xml文件中的an Element Node和all Child Elements.
这是我的xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<data>
<cocktail name="43 Hedonism" id="14">
<name>43 Hedonism</name>
<id>14</id>
</cocktail>
<cocktail name="B-52" id="4">
<name>B-52</name>
<id>4</id>
</cocktail>
</data>
Run Code Online (Sandbox Code Playgroud)
我想删除一个鸡尾酒元素,其中id-attribute为4,存储在变量中.如何告诉我的应用程序只需删除id为4的鸡尾酒元素?
XmlNode.RemoveChild由于Windows Phone 8中不支持/不可用,因此无法正常工作.我编写了以下代码,但我仍然坚持在哪里写出要删除的元素的id.
using System;
using System.IO;
using System.IO.IsolatedStorage;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Resources;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using XmlLocalDelete1.Resources;
using System.Xml;
using System.Xml.Linq;
using System.Text;
namespace XmlLocalDelete1
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent(); …Run Code Online (Sandbox Code Playgroud) 我有一个名为Vector的类,我正在实现乘法运算符,这是我的实现:
public static Object operator *(Vector x, Vector y)
{
//Possible return objects
Matrix multiplicationResultMatrix;
float multiplicationResultScalar = 0f;
if (x.VectorType != y.VectorType)
{
if (x.Length == y.Length)
{
if ((x.VectorType == VectorType.Row) && (y.VectorType == VectorType.Column))
{
for (ulong i = 0; i < x.Length; i++)
{
multiplicationResultScalar += x[i] * y[i];
}
}
else
{
if ((x.VectorType == VectorType.Column) && (y.VectorType == VectorType.Row))
{
multiplicationResultMatrix = new Matrix(x.Length);
for (ulong j = 0; j < x.Length; j++)
{ …Run Code Online (Sandbox Code Playgroud) 要Gnuplot通过指定参数直接使用(在 Linux Ubuntu 16.04 上)命令而不使用提示符,我输入以下示例:
gnuplot -e "filename='DataFile.txt'" SettingsFile
Run Code Online (Sandbox Code Playgroud)
哪里SettingsFile看起来像这样:
plot filename with lines
set title "Total Packets consumption"
set xlabel "Time"
set ylabel "Packets"
set datafile separator ","
pause -1
Run Code Online (Sandbox Code Playgroud)
看起来DataFile.txt像这样:
数据包、时间(以秒为单位):
13392,120
24607,240
23867,360
21764,480
20727,600
20004,720
19719,840
19758,960
19728,1080
20168,1200
19737,1320
19729,1440
20135,1560
20006,1680
21301,1800
19923,1920
20002,2040
19761,2160
20918,2280
22756,2400
22820,2520
23370,2640
22987,2760
22956,2880
24427,3000
23527,3120
24009,3240
23832,3360
23464,3480
23652,3600
11212,3654
Run Code Online (Sandbox Code Playgroud)
第一个问题:
有没有办法将其设置为SettingsFilepng OutputFile ?因此我可以将其作为 Gnuplot 命令的参数输入,就像我对数据文件所做的那样。(我想这样使用它,因为我想从外部代码调用它)
我想实现这样的目标:
gnuplot …Run Code Online (Sandbox Code Playgroud) 我们可以[FromQuery(Name"param")]在控制器操作中使用来指定如何在 uri 中使用传递的参数,如下所示:
[HttpGet()]
public IActionResult GetPeople([FromQuery(Name="page")] int pageNumber, [FromQuery(Name="size")] int pageSize)
{
//Do things
}
Run Code Online (Sandbox Code Playgroud)
在使用复杂类型(例如 where )的情况下如何使用它PeoplePaginationParameters:
public class PaginationParameters
{
public int PageNumber { get; set;}
public int PageSize { get; set;}
}
Run Code Online (Sandbox Code Playgroud)
有没有类似的东西:
[HttpGet()]
public IActionResult GetPeople([FromQuery(Name="page", Name="size")] PaginationParameters paginationParameters)
{
//Do things
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用.ToListAsync()Inside a DbContext的using语句获取linq查询结果,代码:
private async Task<List<String>> GetEntiteesAsync()
{
Task<List<String>> returnValue;
using (var entities = new REPORTEntities())
{
returnValue = (from user in entities.USERs
group user by user.entite into g
select g.Key).ToListAsync();
}
return await returnValue;
}
Run Code Online (Sandbox Code Playgroud)
在运行时,我得到"已经处理了ObjectContext实例,不能再用于需要连接的操作." 如图所示 :

我认为这是由于在returnValue对象仍然像List一样异步接收对象的情况下处理Context这一事实引起的,是否有一种解决方法可以在保留using语句时避免此错误,或者我应该这样做:
private async Task<List<String>> GetEntiteesAsync()
{
Task<List<String>> returnValue;
var entities = new REPORTEntities()
returnValue = (from user in entities.USERs
group user by user.entite into g
select g.Key).ToListAsync();
return await returnValue;
}
Run Code Online (Sandbox Code Playgroud) 我肯定错过了什么,
var t2 = new Task<bool>(() =>
{
return UserName == "Admin";
});
bool x = await t2;
Run Code Online (Sandbox Code Playgroud)
将bool x = await t2;永远不会结束,x没有收到任何东西(而我确信,用户名等于"管理"),不知道到底是怎么回事,请人能向我解释.
这个问题在某种程度上被问到了很多线程,但我找不到一个明确的答案我的情况,我有一个简单的代码,a Button,a Textbox和a ButtonClickEventHandler,后者尽管是这样Async,保持UI阻塞,代码:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private async void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
Task t = new Task(() =>
{
for (int i = 0; i < 10000; i++)
{
Dispatcher.Invoke((()=>
{
TextBox.Text += i.ToString();
}));
}
});
t.Start();
await t;
//Something else
}
}
Run Code Online (Sandbox Code Playgroud)
Xaml:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Button Margin="180,10,185,277" x:Name="Button" Click="ButtonBase_OnClick">
Ok
</Button>
<TextBox Margin="29,83,40,33" x:Name="TextBox"></TextBox>
</Grid> …Run Code Online (Sandbox Code Playgroud) 在OnLaunched我的应用程序期间,我创建了一个这样的文件:
await ApplicationData.Current.LocalFolder.CreateFileAsync(Keys.AdContentBig);
Run Code Online (Sandbox Code Playgroud)
稍后,我将一些字节写入该文件(该文件是一个图像)
该文件写得很好,而且很好:
之后,我想使用ms-appdata:模式检索该文件的 URI以显示它,我要做的是:
var f = await ApplicationData.Current.LocalFolder.GetFileAsync(Keys.AdContentBig);
uriDestination = new Uri("ms-appdata:///local/LocalState/" + f.Name, UriKind.RelativeOrAbsolute);
imageSource = new BitmapImage(uriDestination );
Run Code Online (Sandbox Code Playgroud)
在 XAML 上,一个典型的:
<Image Source="{x:Bind Vm.imageSource, Mode=OneWay}"/>
Run Code Online (Sandbox Code Playgroud)
编译器不会抱怨文件的存在,也不会破坏或其他什么,什么也没有发生,图像也没有显示,当然我做错了什么"ms-appdata:///local/LocalState/",如果我纠正我,或者告诉我还有什么我丢了。
c# ×7
.net ×3
async-await ×3
asynchronous ×3
api ×1
asp.net-core ×1
boxing ×1
events ×1
gnuplot ×1
linq ×1
linux ×1
methods ×1
rest ×1
return ×1
task ×1
winrt-xaml ×1
xaml ×1
xml ×1