|
-
Mar 19th, 2004, 09:14 AM
#1
Thread Starter
New Member
convert an object to string array
Hi,
Can anyone help me to convert an object into a string array or int array using C#?
Thanks
Pal
-
Mar 19th, 2004, 10:19 AM
#2
Addicted Member
Can you give me a little more info?
-
Mar 19th, 2004, 11:35 AM
#3
Lively Member
If it can be done, just say:
object obj = something;
int[] intarray = (int[])obj;
Not totally sure about that but it seems to fit.
-
Mar 19th, 2004, 12:47 PM
#4
Addicted Member
I don't think you can type cast as an array I thought you could only typecast the elements. ;\
-
Mar 22nd, 2004, 05:55 PM
#5
Hyperactive Member
Originally posted by Tewl
I don't think you can type cast as an array I thought you could only typecast the elements. ;\
You can cast arrays:
PHP Code:
int[] intNew={0,1,2,3,7};
foreach(int i in intNew)
Console.WriteLine("Before casting: "+i);
object obj = intNew;
int[] intarray = (int[])obj;
foreach(int i in intarray)
Console.WriteLine("After casting: "+i);
-
Mar 23rd, 2004, 05:56 PM
#6
Addicted Member
-
Mar 25th, 2004, 10:46 AM
#7
Addicted Member
Re: convert an object to string array
Originally posted by pal_amu
Hi,
Can anyone help me to convert an object into a string array or int array using C#?
Thanks
Pal
I'm not sure if these other responses helped you out or not, but another option may be to serialize your object and then deserialize it into a string array.
-
Mar 28th, 2004, 10:59 AM
#8
Hyperactive Member
Code:
object test;
//the object, offcourse you needs to have a value assigned
char[] chrarray = new char[100]; //100 elements for example
chrarray = (test.ToString()).ToCharArray();
some (var-types) classes don't have their own (overridden) ToString() method, but simply inherrit it from the object class.
In that case this will not work. But a lot of classes have their own. (The Integer classes have it, the string class itself has it too.) Instead of the ToString you can also use (string) as shown below...
Code:
object test;
//the object, offcourse you needs to have a value assigned
char[] chrarray = new char[100]; //100 elements for example
chrarray = ((string)test).ToCharArray();
here you go !
greetings
Last edited by BramVandenbon; Mar 29th, 2004 at 11:33 AM.
____________________________________________
Please rate my messages. Thank you!
____________________________________________
Bram Vandenbon
http://www.bramvandenbon.com
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
|