How can I add a file to my banking application?
-
5You want people to go through this dump of code???? Post the relevant section rather – Rahul Sep 24 '15 at 14:30
-
2I don't see any code where you try to save the account & read it back - can you show the bits where you attempt to do that - which appears to be what you are asking. – PaulF Sep 24 '15 at 14:32
-
Right now, I'm using a list. – Adora Sep 24 '15 at 14:39
-
1looking at your classes i suggest you read up a view things on the basics of object oriented design? a person is a teller and an account is a person??? – Marco Forberg Sep 24 '15 at 14:42
2 Answers
A simple google search should get you on your way. Using the following search query: C# Read and Write to a text file give you results such as the following:
How to read from and write to a text file by using Visual C# How to both read and write a file in C# - Stack Overflow c# - Easiest way to read from and write to files - Stack Overflow C# Using StreamWriter - Dot Net Perls
That should get you started. Just a side note, unless the use of generics is required for the assignment, it may be overkill for what you are trying to do.
- 1
- 1
- 809
- 1
- 6
- 16
Cba going through your code, but if you put "using System.IO;" at the top, this following bit will work.
private void Save(string file, string text)
{
File.WriteAllText(file,text);
}
This takes the path of a file (for example, a ".txt" file). And saves given text to it. I'd imagine that for each account you could concatenate all the information like so.
Person person; //example of an instance of "Person" class.
string text = person.PersonName+" : "+person.Gender;//etc
string filename = "C:/examplefilename.txt";
Save(filename, text);
Obviously you would tweak the value of "text" to your own use.
- 1,018
- 7
- 16