如何在arraylist中添加文本框值? [英] How to add textbox value in arraylist?

查看:162
本文介绍了如何在arraylist中添加文本框值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想在arraylist中添加文本框值。我在vb中编写代码但在c#中它不起作用(仅在转换后)。



VB中的代码:

Hi All,
I want to add textbox value in arraylist.I wrote code in vb but in c# it is not working(after conversion only).

My code in VB:

Dim dt As String = txtpissue.Text
Dim tArrList() As String = Nothing
tArrList = dt.ToString.Split("/")
tArrList(2) = Convert.ToInt32(tArrList(2)) +            Convert.ToInt32(txtterm.Text.Trim())
txtmature.Text = tArrList(0) + "/" + tArrList(1) + "/" + tArrList(2)





我在转换错误从int到string时出错。



I got error at conversion error from int to string.

tArrList = dt.ToString.Split("/")
      tArrList(2) = Convert.ToInt32(tArrList(2)) +            Convert.ToInt32(txtterm.Text.Trim())







Thanks& ;问候

Hari




Thanks&Regards
Hari

推荐答案

首先:永远不要使用 ArrayList 。相反,始终使用 System.Collections.Generic.List<> 和其他通用集合类型,但专门的除外。早在.NET Framework的v.2.0中,非泛型集合就已经过时了,当引入泛型时。



你的转换萨满舞是完全不清楚的。 TextBox.Text 是字符串,为什么要从整数转换任何东西?!所有这些皈依者毫无意义。任何东西的字符串表示都是通过方法 ToString 获得的,但是如果你想将一些文本解释为数值,它的类型有方法 Parse TryParse 可能成功也可能不成功。



我想警告你由于缺乏对数据如何工作的理解,许多初学者使用数据的字符串表示而不是数据本身的丑陋趋势。在转换任何东西之前,想想你是否曾经需要它。通常情况下,只有在屏幕上显示数据,存储在文本文件中等时,才应使用数据并使用字符串。



-SA
First and foremost: never use ArrayList. Instead, always use System.Collections.Generic.List<> and other generic collection types, except specialized. The non-generic collections were rendered obsolete as early as of v.2.0 of .NET Framework, when generics were introduced.

You shamanic dance with conversion is completely unclear. TextBox.Text is string, why converting anything from integer?! All these "converts" make no sense. String representation of anything is obtained by the method ToString, but if you want to interpret some text as numeric value, its types have the methods Parse and TryParse which may or may not be successful.

I want to warn you about an ugly trend of many beginners to work with string representation of data instead data itself, due to lack on understanding of how data works. Before "converting" anything, think is you ever need it. Normally, you should work with data and use strings only if you show data on screen, store in text files, etc.

—SA


这一行隐含地将Int转换为String:

This line is converting Int to String implicitely:
tArrList(2) = Convert.ToInt32(tArrList(2)) + Convert.ToInt32(txtterm.Text.Trim())



这当然是因为你的 tArrList(2)是一个字符串



干杯,

Edo


this is of course because your tArrList(2) is a string

Cheers,
Edo


这篇关于如何在arraylist中添加文本框值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆