私は現時点で私を回避している簡単な質問。浮動小数点数を解析するには、下の2行が必要です。これらの2行で私はこれを得る:エラー1暗黙のうちに 'test.Form1.ore'を 'string'に変換することはできない。だから私はテキストボックスをパースして浮動小数点数を解析し、それがテキストボックスに渡されるので、誰かが私に欠けているものを見せることができます。parse float to text box
textBox3.Text = books[0]; // update the first text
textBox4.Text = books[1]; // update the second text
私はこの
textBox4.Text = float.Parse(books[1]); //update the second text
を試みたが、それは参照
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace test
{
public partial class Form1 : Form
{
[Serializable]
public class ore
{
public float Titan;
public float Eperton;
}
ore b1 = null;
ore b2 = null;
public Form1()
{
InitializeComponent();
b2 = new ore();
b1 = new ore();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
float tempFloat;
if (float.TryParse(textBox1.Text, out tempFloat))
{
b1.Titan = tempFloat;
}
else
MessageBox.Show("uh oh");
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
float tempFloat;
if (float.TryParse(textBox1.Text, out tempFloat))
{
b2.Eperton = tempFloat;
}
else
MessageBox.Show("uh oh");
}
private void button1_Click(object sender, EventArgs e)
{
List<ore> oreData = new List<ore>();
oreData.Add(b1);
oreData.Add(b2);
FileStream fs = new FileStream("ore.dat", FileMode.Create);
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(fs, oreData);
fs.Close();
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
}
List<ore> books = new List<ore>();
private void button2_Click(object sender, EventArgs e)
{
FileStream fs = new FileStream("ore.dat", FileMode.Open);
BinaryFormatter bf = new BinaryFormatter();
List<ore> books = (List<ore>)bf.Deserialize(fs);
fs.Close();
if (books.Count > 1)
{
textBox3.Text = float.Parse(books[0]).ToString();//update the first text
textBox4.Text = float.Parse(books[1]).ToString();
//update the second text
}
}
}
}
「うまくいかない」とはどういう意味ですか?エラーメッセージが表示されましたか?外人が空から降りてきたのですか? –
「それはうまくいかない」とはどういう意味ですか?どの部分がうまくいかなかったのですか?間違いましたか?間違った価値観がありますか?あなたのコンピュータは爆発しましたか? –
im sorryエラー 'float.Parse(string)'に最適なオーバーロードされたメソッドが無効な引数を持っています\tは新しいコードのエラーメッセージです – doc