Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?
You are not logged in.
Make a list to an array. Add context by WriteAllText or WriteAllLines.
OPEN stream with,
System.IO.StreamWrite fs = new System.IO.StreamWriter()
Don't forget to dispose (1) and close (2) after you are done.
shh i have returned
Offline
Make a list to an array. Add context by WriteAllText or WriteAllLines.
OPEN stream with,
System.IO.StreamWrite fs = new System.IO.StreamWriter()
Don't forget to dispose (1) and close (2) after you are done.
What do you mean by "open" steam?
Extra:
How do you convert a list into an array?
How do you do File.WriteAllLines() to an array?
Offline
▼Hidden textWhat do you mean by "open" steam?
Extra:
How do you convert a list into an array?How do you do File.WriteAllLines() to an array?
Opening a stream means that you can send data through (on phone, but I think by doing: streamName.Write(File))
I would appreciate if you actually tried looking yourself, since list to array conversion is literally:
Array = List.toArray()
Again thinking for yourself would be nice.
If you would like the textfile to be readable you should first print the size of the array, then loop through each element of the array, print each element and done.
Reading would be first reading the size and then looping the size amount of times to get all elements again without reading elements that are not part of the array.
If the textfile isn't meant to be read you can just do:
File.Write(Array)
You might need to add .toString() to the array name.
P.S. @madiik I don't see why you should covert the List to an Array.
Offline
You don't need to close and dispose.
Closing is enough.
Close()'s code is
public override void Close()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
in the streamwriter,
and
public override void Close()
{
this.Dispose(true);
}
in the streamreader.
And you don't need to call any of them if you wrap it in a 'using'.
You can save items by writing lines and reading them line by line when loading.
You can create a method of yours that makes it easier.
Dictionary<string, string> d = new Dictionary<string, string>();
d.Add("email", "[email protected]");
d.Add("pass", "*****");
d.Add("wid", "PW...");
Save(Application.StartupPath + @"\data.txt", d);
Dictionary<string, string> loadedDictionary = new Dictionary<string, string>();
Load(Application.StartupPath + @"\data.txt", out loadedDictionary);
tbEmail.Text = loadedDictionary["email"];
tbPass.Text = loadedDictionary["pass"];
tbWid.Text = loadedDictionary["wid"];
public void Save(string path, Dictionary<string, string> d)
{
using (System.IO.StreamWriter w = new System.IO.StreamWriter(path))
{
foreach (KeyValuePair<string, string> kv in d)
{
w.WriteLine(kv.Key + ":" + kv.Value);
}
}
}
public void Load(string path, out Dictionary<string, string> d)
{
Dictionary<string, string> dd = new Dictionary<string, string>();
using (System.IO.StreamReader r = new System.IO.StreamReader(path))
{
string line = "";
while ((line = r.ReadLine()) != null)
{
dd.Add(line.Split(':')[0], line.Split(':')[1]);
}
}
d = dd;
}
Offline
You don't need to close and dispose.
Closing is enough.
Close()'s code ispublic override void Close() { this.Dispose(true); GC.SuppressFinalize(this); }
in the streamwriter,
andpublic override void Close() { this.Dispose(true); }
in the streamreader.
And you don't need to call any of them if you wrap it in a 'using'.You can save items by writing lines and reading them line by line when loading.
You can create a method of yours that makes it easier.
Dictionary<string, string> d = new Dictionary<string, string>();
d.Add("email", "[email protected]");
d.Add("pass", "*****");
d.Add("wid", "PW...");Save(Application.StartupPath + @"\data.txt", d);
Dictionary<string, string> loadedDictionary = new Dictionary<string, string>();
Load(Application.StartupPath + @"\data.txt", out loadedDictionary);
tbEmail.Text = loadedDictionary["email"];
tbPass.Text = loadedDictionary["pass"];
tbWid.Text = loadedDictionary["wid"];public void Save(string path, Dictionary<string, string> d)
{
using (System.IO.StreamWriter w = new System.IO.StreamWriter(path))
{
foreach (KeyValuePair<string, string> kv in d)
{
w.WriteLine(kv.Key + ":" + kv.Value);
}
}
}public void Load(string path, out Dictionary<string, string> d)
{
Dictionary<string, string> dd = new Dictionary<string, string>();
using (System.IO.StreamReader r = new System.IO.StreamReader(path))
{
string line = "";
while ((line = r.ReadLine()) != null)
{
dd.Add(line.Split(':')[0], line.Split(':')[1]);
}
}
d = dd;
}
Thanks, DarkDragon! Also, any ideas on how to save items in a ListBox and load them?
Offline
▼"quote"Thanks, DarkDragon! Also, any ideas on how to save items in a ListBox and load them?
You can modify the methods to suit your needs.
public void Save(string path, ListBox l)
{
using (System.IO.StreamWriter w = new System.IO.StreamWriter(path))
{
foreach (var item in l.Items)
{
w.WriteLine(item.ToString());
}
}
}
public void Load(string path, out ListBox l)
{
ListBox ll = new ListBox();
using (System.IO.StreamReader r = new System.IO.StreamReader(path))
{
string line = "";
while ((line = r.ReadLine()) != null)
{
ll.Items.Add(line);
}
}
l = ll;
}
And it seems you're having trouble hiding text.
Use
[spoiler="Spoiler Text Here"]Spoiler Content Here.[/spoiler]
To produce
Offline
Offline
The fact that Visual Studio even warns you about .Close(), it says you should dispose first, then close.
It's safer.
shh i have returned
Offline
It isn't.
Since close obviously executes the Dispose method.
Dispose():
"Releases all resources used by the System.IO.Text(writer/reader) object."
Close():
"Closes the System.IO.Stream(Writer/Reader) object and the underlying stream, and releases any system resources associated with the reader."
Besides, no warnings show up when you use the Close() method.
[Edit] Read about it in stackoverflow.
Offline
The fact that Visual Studio even warns you about .Close(), it says you should dispose first, then close.
Calling Dispose() will do close() then Dispose() if close is already called.
If you Dispose() it will close() then if you try to close() you'll get an exception.
Offline
[ Started around 1732484430.6374 - Generated in 0.082 seconds, 12 queries executed - Memory usage: 1.59 MiB (Peak: 1.79 MiB) ]