Click here to Skip to main content
15,886,823 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
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:
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)


I got error at conversion error from int to string.
C#
tArrList = dt.ToString.Split("/")
      tArrList(2) = Convert.ToInt32(tArrList(2)) +            Convert.ToInt32(txtterm.Text.Trim())



Thanks&Regards
Hari
Posted
Updated 3-Feb-13 19:31pm
v4

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

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

Cheers,
Edo
 
Share this answer
 
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900