Advertisement
parabola949

Untitled

Jun 10th, 2014
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. class Program
  2.     {
  3.         static void Main(string[] args)
  4.         {
  5.             Settings s = new Settings();
  6.             s.Setting1 = 1.45;
  7.             s.Setting2 = 5.04;
  8.  
  9.             using (StreamWriter sw = new StreamWriter("test.txt"))
  10.             {
  11.                 sw.WriteLine(System.Text.Encoding.Default.GetString(Serialize(s)));
  12.             }
  13.         }
  14.  
  15.         public static byte[] Serialize(object anySerializableObject)
  16.         {
  17.             using (var memoryStream = new MemoryStream())
  18.             {
  19.                 (new BinaryFormatter()).Serialize(memoryStream, anySerializableObject);
  20.                 return memoryStream.ToArray();
  21.             }
  22.         }
  23.     }
  24.  
  25.     [SerializableAttribute]
  26.     public class Settings
  27.     {
  28.         public double Setting1;
  29.         public double Setting2;
  30.     }
  31.  
  32.  
  33. /*
  34. OUTPUT
  35.  
  36.     ÿÿÿÿ          JConsoleApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null   ConsoleApplication1.Settings   Setting1Setting2     333333÷?)\Âõ(@
  37.  
  38. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement