Exemplo n.º 1
0
        static void Main(string[] args)
        {
            String[]      strings      = File.ReadAllLines(@"D:\cat.csv");
            CatCollection myCollection = new CatCollection();

            myCollection.Indicators = new Indicator[20];
            var i = 0;

            foreach (var strn in strings)
            {
                var mass = strn.Split(';');

                myCollection.Indicators[i] = new Indicator()
                {
                    id           = mass[0],
                    name         = mass[1],
                    category_ids = new CategoryIdEn()
                    {
                        GBR = mass[7],
                        USA = mass[8],
                        CAN = mass[9],
                    }
                };

                i++;

                string serialized = JsonConvert.SerializeObject(myCollection);

                using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"D:\catEn.json"))
                {
                    file.Write(serialized);
                }
            }
        }
Exemplo n.º 2
0
        static void Main()
        {
            var catCollection = new CatCollection
            {
                new CuteCat {
                    Name = "Pesho"
                },
                new CuteCat {
                    Name = "Ivan"
                }
            };

            foreach (var cats in catCollection)
            {
                Console.WriteLine(cats.Name);
            }

            var coolStack = new CoolStack <int>();

            coolStack.Push(3);
            coolStack.Push(5);
            coolStack.Push(10);
            coolStack.Push(7);
            coolStack.Push(25);
            foreach (var stack in coolStack)
            {
                Console.WriteLine(stack);
            }

            var coolList = new CoolLinkedList <int>();

            coolList.AddHead(1);
            coolList.AddHead(2);
            coolList.AddHead(3);
            coolList.AddHead(4);
            foreach (var i in coolList)
            {
                Console.WriteLine(i);
            }
            SomeMethodsWithParams(1, new[] { "1", "1", "1" });
            SomeMethodsWithParams(2, new[] { "1", "2" });
            SomeMethodsWithParams(3, new[] { "3" });
            SomeMethodsWithParams(5, "3");
            SomeMethodsWithParams(5, "3", "3", "3");
            SomeMethodsWithParams(6, "3", "2", "445");
            SomeMethodsWithParams(6);
        }
Exemplo n.º 3
0
        public static void Test1()
        {
            //声明一个猫咪对象
            var cWhite = new Cat {
                Color = "White", Speed = 10, Saying = "White or black,  so long as the cat can catch mice,  it is a good cat"
            };
            var cBlack = new Cat {
                Color = "Black", Speed = 10, Saying = "White or black,  so long as the cat can catch mice,  it is a good cat"
            };

            CatCollection cc = new CatCollection {
                Cats = new Cat[] { cWhite, cBlack }
            };

            //序列化这个对象
            XmlSerializer serializer = new XmlSerializer(typeof(CatCollection));

            //将对象序列化输出到控制台
            serializer.Serialize(Console.Out, cc);
        }
Exemplo n.º 4
0
        public static void XMLDemo6()
        {
            Cat cWhite = new Cat {
                Color = "White", Speed = 10, Saying = "White cat"
            };
            Cat cBlack = new Cat {
                Color = "Black", Speed = 15, Saying = "Black cat"
            };

            CatCollection cc = new CatCollection
            {
                Cats = new[] { cWhite, cBlack }
            };

            //序列化这个对象
            XmlSerializer serializer = new XmlSerializer(typeof(CatCollection));

            XmlSerializerNamespaces xmlSerializerNamespaces = new XmlSerializerNamespaces();

            xmlSerializerNamespaces.Add("", "");
            serializer.Serialize(Console.Out, cc, xmlSerializerNamespaces);
        }