当前位置: 首页>>代码示例>>C#>>正文


C# Train.AddRoom方法代码示例

本文整理汇总了C#中Train.AddRoom方法的典型用法代码示例。如果您正苦于以下问题:C# Train.AddRoom方法的具体用法?C# Train.AddRoom怎么用?C# Train.AddRoom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Train的用法示例。


在下文中一共展示了Train.AddRoom方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            //  FileWatcher.Init(".", "*.*");

            Train train = new Train(5);

            train.AddCoach(new Coach(1, CoachType.Coupe));
            train.AddCoach(new Coach(2, CoachType.Coupe));

            train.AddRoom(1, new Room(4, 2));
            train.AddRoom(1, new Room(4, 1));
            train.AddRoom(2, new Room(2, 2));
            train.AddRoom(2, new Room(2));

            Rijndael rijndael = Rijndael.Create();

            FileStorage storage = new FileStorage();

            storage.AddFilter(new Storage.Filters.CryptFilter(rijndael.IV, rijndael.Key));
            storage.AddFilter(new Storage.Filters.ZipFilter());

            Console.WriteLine("Before writing text file: \n");
            Console.WriteLine(train);

            storage.WriteTrain("train.txt", train, new TextFormatter());
            train = storage.ReadTrain("train.txt", new TextFormatter());

            Console.WriteLine("After reading text file: \n");
            Console.WriteLine(train);

            Console.WriteLine("Before writing binary file: \n");
            Console.WriteLine(train);

            storage.WriteTrain("train.dat", train, new BinaryFormatter());
            train = storage.ReadTrain("train.dat", new BinaryFormatter());

            Console.WriteLine("After reading binary file: \n");
            Console.WriteLine(train);

            Thread.Sleep(200);

            Console.WriteLine("\nDelete train.txt...");
            File.Delete("train.txt");

            Thread.Sleep(200);

            Console.WriteLine("\nRename train.dat...");
            try
            {
                File.Move("train.dat", "train_renamed.dat");
            }
            catch (IOException e)
            {
                File.Delete("train_renamed.dat");
                Thread.Sleep(200);
                File.Move("train.dat", "train_renamed.dat");
            }

            DomXml domxml = new DomXml();
            XmlDocument xml = domxml.SaveTrain(train);
            XDocument doc = XDocument.Parse(xml.OuterXml);
            TextWriter writer = new StreamWriter("train_dom.xml");
            writer.Write(doc.ToString());
            writer.Close();

            LinqXml linqxml = new LinqXml();
            doc = linqxml.SaveTrain(train);
            writer = new StreamWriter("train_linq.xml");
            writer.Write(doc.ToString());
            writer.Close();

            BinarySerialization bs = new BinarySerialization();
            FileStream fs = new FileStream("binary.dat", FileMode.Create);
            bs.Serialize(fs, train);
            fs.Close();

            fs = new FileStream("binary.dat", FileMode.Open);
            Console.WriteLine("\nBinary deserializaton:");
            Console.WriteLine(bs.Deserialize(fs));
            fs.Close();

            XmlSerialization xs = new XmlSerialization();
            fs = new FileStream("xml_s.xml", FileMode.Create);
            xs.Serialize(fs, train);
            fs.Close();

            fs = new FileStream("xml_s.xml", FileMode.Open);
            Console.WriteLine("\nXML deserializaton:");
            Console.WriteLine(xs.Deserialize(fs));
            fs.Close();

            Console.ReadLine();
        }
开发者ID:Ozerich,项目名称:labs,代码行数:93,代码来源:Program.cs


注:本文中的Train.AddRoom方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。