Cander
Apr 2nd, 2002, 10:16 AM
What do you guys think of my first C# app? Anything you think could be done better..or any syntax areas that should be done differently?
// created on 04/02/2002 at 9:50 AM using SharpDevelop http://www.icsharpcode.net
// by Chris Andersen(aka Cander)
// The following a Serialize/Deserialize to/from SOAP for a string array. Perfect
// for easily getting and saving configuration files.
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Soap;
public class SerializeClass
{
public static void Main(string[] args)
{
string[] a;
a = new string[2];
a[0] = "Hello";
a[1] = "Goodbye";
SerializeArray(a,"test.xml");
DeSerializeArray("test.xml");
}
public static void SerializeArray(string[] arList, string fname)
{
// Serialize the passed in string array to a SOAP message into the specified
// xml file.
Console.WriteLine(arList[0]);
Console.WriteLine(arList[1]);
Console.WriteLine("Please wait while settings are saved...");
FileStream fstream = new FileStream(fname, FileMode.Create, FileAccess.Write);
SoapFormatter soapFormat = new SoapFormatter();
try
{
soapFormat.Serialize(fstream, arList);
}
finally
{
fstream.Close();
Console.WriteLine("Soap transfer is complete!");
}
}
public static void DeSerializeArray(string fname )
{
// Deserialize the SOAP message back into a string array.
FileStream fstream = new FileStream(fname, FileMode.Open, FileAccess.Read);
SoapFormatter soapFormat = new SoapFormatter();
string[] b;
try
{
b = (string[])soapFormat.Deserialize(fstream);
}
finally
{
fstream.Close();
Console.WriteLine("Soap transfer is complete!");
}
Console.WriteLine(b[0]);
Console.WriteLine(b[1]);
}
}
// created on 04/02/2002 at 9:50 AM using SharpDevelop http://www.icsharpcode.net
// by Chris Andersen(aka Cander)
// The following a Serialize/Deserialize to/from SOAP for a string array. Perfect
// for easily getting and saving configuration files.
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Soap;
public class SerializeClass
{
public static void Main(string[] args)
{
string[] a;
a = new string[2];
a[0] = "Hello";
a[1] = "Goodbye";
SerializeArray(a,"test.xml");
DeSerializeArray("test.xml");
}
public static void SerializeArray(string[] arList, string fname)
{
// Serialize the passed in string array to a SOAP message into the specified
// xml file.
Console.WriteLine(arList[0]);
Console.WriteLine(arList[1]);
Console.WriteLine("Please wait while settings are saved...");
FileStream fstream = new FileStream(fname, FileMode.Create, FileAccess.Write);
SoapFormatter soapFormat = new SoapFormatter();
try
{
soapFormat.Serialize(fstream, arList);
}
finally
{
fstream.Close();
Console.WriteLine("Soap transfer is complete!");
}
}
public static void DeSerializeArray(string fname )
{
// Deserialize the SOAP message back into a string array.
FileStream fstream = new FileStream(fname, FileMode.Open, FileAccess.Read);
SoapFormatter soapFormat = new SoapFormatter();
string[] b;
try
{
b = (string[])soapFormat.Deserialize(fstream);
}
finally
{
fstream.Close();
Console.WriteLine("Soap transfer is complete!");
}
Console.WriteLine(b[0]);
Console.WriteLine(b[1]);
}
}