これはあなたがここで取得する最も一般的な質問の1つですが、どんなに難しい検索をしても。私は、Windowsでのプロジェクトのためのキーチェーンアプリケーションを構築していC#クラスリストの作成<>/Dictionary <>、データを上書きせずにデータベースとしての.txtファイルへの書き込みと読み取り
フォームアプリケーション、そしてできるだけ容易この概念を理解する目的のために私は、これはむしろ辞書//はiList
より>一覧<と一緒に行きました私が使用しているクラス:
public class Account
{
public static List<Account> myAccountList = new List<Account>();
public string Domain; //this is supposed to be google/skype/facebook
public string Email;
public string Username;
public string Password;
public Account (string domain, string email, string username, string password)
{
Domain = domain;
Email = email;
Username = username;
Password = password;
myAccountList.Add(new Account(domain, email, username, password)); //constructor calls the new list instance
}
private static void SaveToFile()
{
System.IO.File.WriteAllLines(@accountdb.txt, myAccountList);
}
private static void ReadFromFile() // this is meant to be used as authentication in my main form, it isn't necessary right now..
{
System.IO.File.ReadAllLines(@accountdb.txt);
}
}
私はこれで夫婦の問題を持っている:
- 私はFiに書き込むための機能Saveメソッドを作成することはできません。 le、私はいくつかの方法を試しました
System.IO
- リストを1次元配列に変更しても、それは絶えず上書きされます。後でMySQLをシミュレートしたいと思います。
コンストラクタを呼び出すボタンのClickイベント:
private void buttonSave_Click(object sender, EventArgs e)
{
string domain, email, username, password;
domain = comboboxDomain.Text;
email = textboxEmail.Text;
username = textboxUsername.Text;
password = textboxPassword.Text;
//Checking for correct EMAIL
if (!textboxEmail.Text.Contains("@") && (!textboxEmail.Text.Contains(".")))
{
MessageBox.Show("Invalid Email Format");
}
else
{
Account account = new Account(domain, email, username, password);
}
}
あなたの質問は何ですか? – maccettura
@maccetturaリストをファイルに書き込む方法が間違っていて、保存メソッドが.txtファイルの以前の資格情報を上書きしないようにする方法 –