Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Web.Script.Serialization; // Assembly: System.Web.Extensions (in System.Web.Extensions.dll)
- namespace SimpleTests
- {
- class Program
- {
- public class SerializeInfo
- {
- public string Label { get; private set; }
- public string[][] Data { get; private set; }
- public SerializeInfo(string lable, Dictionary<DateTime, string> data)
- {
- Label = lable;
- Data = data.Select(p => new[]
- {
- p.Key.ToString("d",CultureInfo.CreateSpecificCulture("en-US").DateTimeFormat),
- p.Value
- }).OrderBy(d => d[0]).ToArray();
- }
- }
- static void Main(string[] args)
- {
- var js = new JavaScriptSerializer();
- var timeline = new Dictionary<DateTime, string>
- {
- {new DateTime(2000, 1, 1), "3.2"},
- {new DateTime(2002, 2, 2), "5.2"},
- {new DateTime(2003, 2, 2), "8.1"}
- };
- Console.WriteLine(js.Serialize(new SerializeInfo("Europe (EU27)", timeline)));
- // {"Label":"Europe (EU27)","Data":[["1/1/2000","3.2"],["2/2/2002","5.2"],["2/2/2003","8.1"]]}
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment