存储文本框值时无法获得正确的输出(not getting correct output when storing textbox values)

   IT问题网   2021-01-22 00:00:00

问 题

对于textbox1中给出的任何数值,我一直将消息框中的输出设为"0"。你可以修改我的代码吗?谢谢



  public  部分  mainwindow:window 
{
public double [] average = new double [ 5 ];
}
私有 void button1_click( object sender,routedeventargs e)
{
average [ 0 ] = convert.todouble(textbox1.text);
messagebox.show(convert.tostring(average [ 0 ]));
}




ps:我也尝试过.textbox1.text,但它没有用。你能否解释一下这个''这个''关键字的确切含义?谢谢





感谢大家的回复,但我的目标不是在文本框中显示值,而是将其存储在数组。我打算每次单击按钮时在双数组中存储一个新值。我希望代码是这样的。

 private button_click()
{
int i = 0;
代码将文本框中的当前值存储到双数组[i]中,并可能将其显示在消息框
....
i ++;
textbox1.clear();
}

解决方案

这是什么意思: http://msdn.microsoft.com/en-us/library/dk1507sz(v = vs.80)的.aspx[ ^]



你最好做什么

  double  mycheckdouble =  0 ; 
if double .tryparse(textbox1.text, out mycheckdouble)
messagebox.show( string .format(" 找到的值{0}",mycheckdouble));
else
messagebox。显示(" 无法将值转换为double");

convert.todouble() [ ^ ]当输入为空时返回0,空字符串或"0"。所以要么你有多个 textbox 并且使用了错误的一个,要么你没有改变 textbox



此是对t的引用他目前的班级实例。请参阅文档此(c#参考) [ ^ ]

  public   partial   mainwindow:window 
{
public double [] average = new double [ 5 ];

public static int i = 0 ;

受保护 void addtoarray()
{
if (i!= 5 amp;amp; i lt; ; 5
{
average [i] = convert.todouble(txtbox.text);
i ++;
}
}

}
// 然后将mwthod称为按钮单击,您可以编写代码以停止单击按钮,如果它是5次

标签:存储文本框无法没法获得取得获取正确输出



分享:

  • 微信
  • QQ好友
  • QQ空间
  • 新浪微博


热门推荐

如何在asp.net中调用客户端的服务器端功能?(How to call server side function in client side in asp.net)

problem how to call server side function in client side i ...

将Excel数据导入并更新到sql中(Import and Update Excel data into sql)

problem hi, am working on a project which import data int ...

如何在asp中使用我的sql(How to use my sql in asp)

problem hi sir/madam, in our application of asp,we have ...

如何制作wpf鼠标事件?(How can made wpf mouse event )

problem how can made wpf mouse event see more: c# please ...

如何在包含三个用于用户输入的asp.net服务器控件的表中动态添加行(how to add rows dynamically in the table containing three asp.net server controls for user input)

problem hi a table having 5 rows and 3 columns, each ro ...

如何将string []数组值分配给cookie(How to assign a string[] array values to a cookie)

problem i have a string array and it is filling by databa ...

在基本MSI项目中从InstallShield显示消息“安装程序需要64位处理器”(Show message “Setup requires a 64Bit processor” from InstallShield in basic MSI project)

problem i am using installshield 11 and creat ...

c ++编程语言(c++ programming language)

problem hello all, i am looking to design c++ code for is ...

MySql DB(如何在部署时添加DB)(MySql DB(how to add DB at the time of deployment))

problem hello, i am going to deploy(c#.net with mysql 5.0 ...

如何为15个链接按钮单击事件实现相同的代码(How to implement same code for 15 linkbutton click events)

problem hi, i want to bind a tree in horizon ...

在数据网格中更改字段的名称(change field's name in a datagrid)

problem how can i change name of the each header columns ...

使用多个mdi表单(working with mutiple mdi forms)

problem hello i have a c sharp application, which contai ...

更改Html对象Zindex(Change Html Object Zindex)

problem hi all i have an object in my page. i ...

GDI +中发生一般错误的问题。(problem with A generic error occurred in GDI+.)

problem hi all when i want save image from fileupload fa ...

编写非肥皂网服务(Writing Non soap web service)

problem please let me know how to write a non ...

在asp.net和c#中动态创建按钮(Dynamically created button in asp.net and c#)

problem hi, i am creating online examination ...

文件上传问题,找不到文件(File Upload problem, file not found)

problem hi, from my asp.net form, i am trying ...

请在下拉列表中解决错误(please solve error in dropdown list)

problem please solve the error i have 2 dropdownlist. in ...

更改属性上的ReadOnly属性不起作用(Change ReadOnly attribute on property doesn't work)

problem i''ve tried to change a readonly attr ...

我如何分割我的表格(how do i split my form)

problem ok i want to split my form in half so on the left ...