class ComplexValue
{
const string m_Alphabet = "abcdefghijklmnopqrstuvwxyz";
int First { get; set; }
char[] Middle { get; set; };
int Last { get; set; }
public ComplexValue(string input)
{
First = int.Parse(input.Substring(0, 1));
Middle = input.Substring(1, 3).ToCharArray();
Last = int.Parse(input.Substring(input.Length - 1, 1));
}
public string Value() => $"{First}{new string(Middle)}{Last}";
private int IncrementLast()
{
Last++;
if (Last > 9) { Last = 0; return 1; }
return 0;
}
private int DecrementLast()
{
Last--;
if (Last < 0) { Last = 9; return 1 }
return 0;
}
private char IncrementChar(char c, out bool carry)
{
carry = false;
c++;
if (c > m_Alphabet[m_Alphabet.Length -1] )
{
c = m_Alphabet[0];
carry = true;
}
return c;
}
private char DecrementChar(char c, out bool borrow)
{
borrow = false;
c--;
if (c < m_Alphabet[0])
{
c = m_Alphabet[m_Alphabet.Length - 1];
borrow = true;
}
return c;
}
private int IncrementMiddle()
{
int pos = Middle.Length - 1;
while (pos > 0)
{
Middle[pos] = IncrementChar(Middle[pos], out bool carry);
if (!carry) return 0;
pos--;
}
return 1;
}
private int DecrementMiddle()
{
int pos = Middle.Length - 1;
while (pos > 0)
{
Middle[pos] = DecrementChar(Middle[pos], out bool borrow);
if (!borrow) return 0;
pos--;
}
return 1;
}
public void Increment()
{
if (IncrementLast() > 0)
{
if (IncrementMiddle() > 0) First++;
}
}
public void Decrement()
{
if (DecrementLast() > 0)
{
if (DecrementMiddle() > 0) First--;
}
}
}
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace TasksSample
{
public class Worker
{
private int id;
public Worker(int id)
{
this.id = id;
}
public void DoHardWork()
{
Console.WriteLine($"Task {this.id} started.");
Random rng = new Random();
int delay = rng.Next(1000, 10000);
Thread.Sleep(delay);
Console.WriteLine($"Task {this.id} finished after {delay} ms.");
} // DoHardWork
} // class Worker
class Program
{
static void Main(string[] args)
{
TaskFactory fact = new TaskFactory();
int TaskCount = 10;
List<Task> myTasks = new List<Task>();
for (int id = 0; id < TaskCount; ++id)
{
Worker w = new Worker(id);
myTasks.Add(fact.StartNew(() => w.DoHardWork()));
}
Task.WaitAll(myTasks.ToArray());
} // void Main
} // class Program
} // namespace TasksSample
public class XmlEntry
{
public DateTime Date { get; set; }
public float[] Values { get; set; }
} // class XmlEntry
public IEnumerable<XmlEntry> ReadFile(string filename)
{
XmlDocument doc = new XmlDocument();
doc.Load(filename);
return doc.SelectNodes("dataset/data/datum") // Здесь возможно подредактировать путь надо, у вас XML обрезан
.OfType<XmlElement>()
.Select(e => new XmlEntry
{
Date = DateTime.Parse(
e.ChildNodes.OfType<XmlElement>()
.Where(cn =>
cn.Attributes["type"].Value.Equals("date")).FirstOrDefault().InnerText),
Values =
e.ChildNodes.OfType<XmlElement>()
.Where(cn =>
cn.Attributes["type"].Value.Equals("float"))
.Select(node => float.Parse(node.InnerText, System.Globalization.CultureInfo.InvariantCulture))
.ToArray()
});
} // ReadFile