|
-
Dec 23rd, 2007, 10:42 AM
#1
Thread Starter
Addicted Member
[2.0] How to copy array to textbox array
Hi:
How can I copy Array to Textbox Array? Can it be done without using Looping? As both are objects (Am I right ?) Then It should be able to just copy the normal way , a=b ?
-
Dec 23rd, 2007, 05:43 PM
#2
Re: [2.0] How to copy array to textbox array
No, you cannot simply do something like a=b. As you say, arrays are objects. If you do that then you'll simply have two variables referring to the same array object.
Copy an array of what? If it's an array of TextBoxes then you can just call Array.Copy. I'm guessing that it's not an array of TextBoxes though. If my guess is accurate and its an array of Strings then you could use the Array.ForEach method, but that's not really any easier than an explicit loop.
-
Dec 23rd, 2007, 08:44 PM
#3
Thread Starter
Addicted Member
Re: [2.0] How to copy array to textbox array
 Originally Posted by jmcilhinney
No, you cannot simply do something like a=b. As you say, arrays are objects. If you do that then you'll simply have two variables referring to the same array object.
Copy an array of what? If it's an array of TextBoxes then you can just call Array.Copy. I'm guessing that it's not an array of TextBoxes though. If my guess is accurate and its an array of Strings then you could use the Array.ForEach method, but that's not really any easier than an explicit loop.
Yeah jim, it' an array of string. I'm wondering if (using Backgroundworker), e.result can hold an array of string, and is able to be cast to an string array ; then since Textbox array is an object, why it is not able to be cast just like array of string ?
An implicit error was throwed if I try to cast. Direct cast e.result to string array was so convenient and fast. Normally with Looping ( be it foreach or For), the UI normally will look sluggish.
my objective is looking at the fastest way of assigning value to Textboxes and array.
So how should I approach this?
Thanks and Merry Christmas to you Jim
-
Dec 23rd, 2007, 09:47 PM
#4
Re: [2.0] How to copy array to textbox array
The e.Result property is type Object, specifically so that it can refer to any type of object.
Casting is not magic. A variable has to refer to an object of a specific type to be able to be cast as that type. If you assign a String array to the e.Result property in the DoWork event handler, that same String array is what you get back from the e.Result property in the RunWorkerCompleted event. How can that String array magically become a TextBox array?
If someone gives me a carton of eggs to give to you, will I give you a carton of beer just because that's what you want? Of course not. A carton of eggs is a carton of eggs, not a carton of beer. Likewise an array of Strings is an array of String, not an array of TextBoxes. One cannot magically become the other just because it's convenient.
Sure a TextBox array is an object, as is a String array. But then, a Form is an object too, as is a DataTable, as is a StreamWriter, as is an ArrayList. None of them can magically become a TextBox array any more than a String array can. You can only successfully cast a variable as a particular type if it actually refers to an object of that type.
You have no choice but to use a loop. If your UI lags when you do this then you must have an awful lot of TextBoxes, in which case you might consider a redesign.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|