samedi 6 février 2016

C# Random method

I just developed 1 program, whats generates random numbers and letters and after just write result into XML file. But there is a problem like, if i press button to generate once, it doesn't do anything, if i press button second time in arrow it generates.

private static void ToXml(string xml_uri, string value)
{
    XDocument doc;
    if (File.Exists(xml_uri))
        doc = XDocument.Load(xml_uri);
    else
        doc = new XDocument(new XDeclaration("1.0", "UTF-8", "yes"), new XElement("RndStr"));

    doc.Element("RndStr").Add(new XElement("Str", value));

    doc.Save(xml_uri);
}

private void button1_Click(object sender, EventArgs e)
{
    string file_name = "file.xml";

    if (textBox1.Text.Length > 0)
        ToXml(file_name, textBox1.Text);

    textBox1.Text = RndStr(10);
}




Aucun commentaire:

Enregistrer un commentaire