ABCsharp

Hi, i understood that there are lots of posts regarding saving datas. However, i couldnt find any post regarding saving strings and integers in C# language(Visual Basic 2005). Im working on an emulator, and im trying to save data typed in textboxes, and later retrieve the data. However, i cant find and i dont know the suitable coding for it. Can anybody help or at least show me the link where i can find any resourceful informations. Thank you.



Re: Visual C# General Saving Strings & Integers in C#!

Mark Dawson

Hi,

you should look into XML, that will give you an easy place to store and retrieve a set of data. This might be a good place to start learning more: http://www.functionx.com/vcsharp/xml/Lesson01.htm

Mark.






Re: Visual C# General Saving Strings & Integers in C#!

dape

Hi,

You need to be a little more precise; how do plan to persist your data

(Database, csv file, xml file, ... )

Best Regards,

Daniel





Re: Visual C# General Saving Strings & Integers in C#!

ABCsharp

I've been researching online, and i found out that using xml file seems to be the most popular method. However I am still having some trouble using xml as i am still new at it. Help



Re: Visual C# General Saving Strings & Integers in C#!

Peter Ritchie

Save it where If you want to save strings and integers to a binary file:

Code Snippet

using System;

using System.IO;

using System.Runtime.Serialization;

using System.Runtime.Serialization.Formatters.Binary;

public class Program {

public static void Main(){

BinaryFormatter binaryFormatter = new BinaryFormatter();

if(File.Exists("data"))

{

using(Stream stream = File.Open("data", FileMode.Open))

{

String text = binaryFormatter.Deserialize(stream) as String;

if(!String.IsNullOrEmpty(text))

{

Console.WriteLine("Text: {0}", text);

}

else

{

Console.WriteLine("no text");

}

int number = (int)binaryFormatter.Deserialize(stream);

Console.WriteLine("Number: {0}", number);

}

}

else

{

using(Stream stream = File.Open("data", FileMode.Create))

{

binaryFormatter.Serialize(stream, "Text");

binaryFormatter.Serialize(stream, 42);

}

}

}

}