Hi,
Can anyone help me to convert an object into a string array or int array using C#?
Thanks
Pal
Printable View
Hi,
Can anyone help me to convert an object into a string array or int array using C#?
Thanks
Pal
Can you give me a little more info?
If it can be done, just say:
object obj = something;
int[] intarray = (int[])obj;
Not totally sure about that but it seems to fit.
I don't think you can type cast as an array I thought you could only typecast the elements. ;\
You can cast arrays:Quote:
Originally posted by Tewl
I don't think you can type cast as an array I thought you could only typecast the elements. ;\
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);
i stand corrected then
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.Quote:
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
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...
here you go !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();
greetings