Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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)
 
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&Regards
Hari
Posted 3-Feb-13 18:41pm
Edited 3-Feb-13 19:31pm
v4
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

This line is converting Int to String implicitely:
tArrList(2) = Convert.ToInt32(tArrList(2)) + Convert.ToInt32(txtterm.Text.Trim())
this is of course because your tArrList(2) is a string
 
Cheers,
Edo
  Permalink  

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



Advertise | Privacy | Mobile
Web04 | 2.8.140709.1 | Last Updated 4 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid