本文整理汇总了C#中Train.AddCoach方法的典型用法代码示例。如果您正苦于以下问题:C# Train.AddCoach方法的具体用法?C# Train.AddCoach怎么用?C# Train.AddCoach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Train
的用法示例。
在下文中一共展示了Train.AddCoach方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadTrain
public override Train ReadTrain(Stream stream)
{
sr = new StreamReader(stream);
Train train = new Train(Int32.Parse(sr.ReadLine()));
int count = Int32.Parse(sr.ReadLine());
for (int i = 0; i < count; i++)
train.AddCoach(ReadCoach());
return train;
}
示例2: ReadTrain
public override Train ReadTrain(Stream stream)
{
sr = new BinaryReader(stream);
Train train = new Train(sr.ReadInt32());
int count = sr.ReadInt32();
for (int i = 0; i < count; i++)
train.AddCoach(ReadCoach());
return train;
}
示例3: 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();
}