1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
using System; using System.IO; class ConsoleApplication { const string fileName = "AppSettings.dat"; static void Main() { WriteDefaultValues(); DisplayValues(); } public static void WriteDefaultValues() { using (BinaryWriter writer = new BinaryWriter(File.Open(fileName, FileMode.Create))) { writer.Write(1.250F); writer.Write(@"c:\Temp"); writer.Write(10); writer.Write(true); } } public static void DisplayValues() { float aspectRatio; string tempDirectory; int autoSaveTime; bool showStatusBar; if (File.Exists(fileName)) { using (BinaryReader reader = new BinaryReader(File.Open(fileName, FileMode.Open))) { aspectRatio = reader.ReadSingle(); tempDirectory = reader.ReadString(); autoSaveTime = reader.ReadInt32(); showStatusBar = reader.ReadBoolean(); } Console.WriteLine("Aspect ratio set to: " + aspectRatio); Console.WriteLine("Temp directory is: " + tempDirectory); Console.WriteLine("Auto save time set to: " + autoSaveTime); Console.WriteLine("Show status bar: " + showStatusBar); } } } |