小编Dav*_*vid的帖子

XmlWriter将所有内容写入一行

我正在写一个XML文件,但是当我去阅读它时,它们都在同一条线上.

有人可以看看我的代码,并知道为什么它们都出现在同一行而不是正确的格式.

您应该看到的代码是编写几个节点,然后编写代码,名称,公式等等......还检查数据行8及更高版本中的公式是不重复的

var exportFile = "c:\\temp\\export.xml";
XmlWriter xmlWriter = XmlWriter.Create(exportFile);

xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("designExport");
xmlWriter.WriteStartElement("designs");
xmlWriter.WriteStartElement("design");
foreach (DataRow dr in xltbl.Rows)
{
    xmlWriter.WriteStartElement("code");
    xmlWriter.WriteString(dr[0].ToString());
    xmlWriter.WriteEndElement();
    xmlWriter.WriteStartElement("name");
    xmlWriter.WriteString(dr[1].ToString());
    xmlWriter.WriteEndElement();
    for (var i = 2; i < xltbl.Columns.Count; i++)
    {
        if (i >= 8 && dr[i] != dr[i - 8])
        {
            if (string.IsNullOrEmpty(dr[i].ToString())) continue;
            xmlWriter.WriteStartElement("forumula");
            xmlWriter.WriteString(dr[i].ToString());
            xmlWriter.WriteEndElement();
            xmlWriter.WriteStartElement("coverage");
            xmlWriter.WriteString("0");
            xmlWriter.WriteEndElement();
            xmlWriter.WriteStartElement("usageFactor");
            xmlWriter.WriteString("0");
            xmlWriter.WriteEndElement();
        }
    }
}
xmlWriter.WriteEndDocument();
xmlWriter.Close();
Run Code Online (Sandbox Code Playgroud)

c# xml xmlwriter

0
推荐指数
1
解决办法
1532
查看次数

C++ QuickSort没有排序

void quickSort(vector<double> unsortedData, int leftBound, int rightBound) {

    if (leftBound < rightBound) {
        double i = partitionStep(unsortedData, leftBound, rightBound);
        quickSort(unsortedData, leftBound, i-1);
        quickSort(unsortedData, i + 1, rightBound);
    }
}

double partitionStep(vector<double> unsortedData, int leftBound, int rightBound) {

    double pivot = unsortedData[rightBound];

    while (leftBound <= rightBound) {

        while ((unsortedData[leftBound] < pivot)) {
            leftBound++;
        }
        while ((unsortedData[rightBound] > pivot)) {
            rightBound--;
        }

        if (unsortedData[leftBound] == unsortedData[rightBound]) {
            leftBound++;
        } else if (leftBound < rightBound) {
            double temp = unsortedData[leftBound];
            unsortedData[leftBound] = unsortedData[rightBound]; …
Run Code Online (Sandbox Code Playgroud)

c++ sorting vector quicksort

0
推荐指数
1
解决办法
74
查看次数

配置等待 IObservable&lt;T&gt;

我在使用阻塞代码时遇到死锁Task.Wait(),等待async内部等待 Rx LINQ 查询的方法。

这是一个例子:

public void BlockingCode() 

{

    this.ExecuteAsync().Wait();

}

public async Task ExecuteAsync() 

{

    await this.service.GetFooAsync().ConfigureAwait(false);

    //This is the RX query that doesn't support ConfigureAwaitawait 
    await this.service.Receiver
      .FirstOrDefaultAsync(x => x == "foo")
      .Timeout(TimeSpan.FromSeconds(1));

}
Run Code Online (Sandbox Code Playgroud)

所以,我的问题是是否有任何等效的 ConfigureAwait on awaitable IObservable 以确保延续不会在相同的SynchronizationContext.

c# asynchronous system.reactive async-await

0
推荐指数
1
解决办法
936
查看次数

c#字典自动打破for循环,

Dictionary<double, Tuple<int,int>> dictionary = new Dictionary<double, Tuple<int,int>>();

for (int i = 0; i < x.Length; i++)
    for (int j = i+1; j < x.Length; j++)
    {
        double weight = Math.Round(Math.Sqrt(Math.Pow((x[i] - x[j]), 2) + Math.Pow((y[i] - y[j]), 2)), 2);
        string edges = i + "-" + j + "-" + weight;
        listBox1.Items.Add(edges);
        Tuple<int, int> tuple = new Tuple<int, int>(i, j);
        dictionary.Add(weight, tuple);
    }

var list = dictionary.Keys.ToList();
list.Sort();

foreach (var key in list)
{
    string a = dictionary[key].Item1 + "--" …
Run Code Online (Sandbox Code Playgroud)

c# dictionary loops for-loop break

0
推荐指数
1
解决办法
105
查看次数