PDA

View Full Version : Any expert with C#? HELP!


mrxafiar
09-15-2008, 04:40 PM
Hello! I recently started studing C# and now I got this lil homework to hand in.
I have to save the contacts of an agenda I created in a file (.txt, .dat w/e). So my problem is, I dunno how to do it!
I made a struct of Contacts which can save the name of the contact, its phone, email. When I try to use the writer.WriteLine(contact); it saves the namespace.class.variabletype, but i need to save the VALUE not its direction.

Can anyone help me, please?

Rampid_Justin
09-15-2008, 05:24 PM
Don't you have a book?

If not..
http://www.google.com/search?hl=en&q=c+sharp+write+text+file&btnG=Google+Search&aq=2&oq=c+sharp+write+

First result; http://www.csharp-station.com/HowTo/ReadWriteTextFile.aspx

mrxafiar
09-15-2008, 05:30 PM
Don't you have a book?

If not..
http://www.google.com/search?hl=en&q=c+sharp+write+text+file&btnG=Google+Search&aq=2&oq=c+sharp+write+

First result; http://www.csharp-station.com/HowTo/ReadWriteTextFile.aspx

TY Justin, but ive tried that. I think it has to do with the fact that Im trying to save a struct?
Heres the struct I have:

struct Contact{
public string name;
public string tel;
public string email;
}

with that struct, I create in Main the variable:
Contact[] cont = new Contact[40];

And 'cont' is what I want to save in a .txt file. When I try to use the method it shows on that site you posted, it only saves the direction the variable is, like, ConsoleApp1.Program.Agenda+Contact[] thats what it saves instead of the values of the variable.